提交记录 5932


用户 题目 状态 得分 用时 内存 语言 代码长度
nantf noi18d. 【NOI2018】屠龙勇士 Accepted 100 560.902 ms 8620 KB C++ 2.41 KB
提交时间 评测时间
2018-09-11 17:20:02 2020-08-01 00:36:41
#include<cstdio>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=100010;
multiset<ll> mts;
int t,n,m;
bool spec,exist,same;
ll hp[maxn],rec[maxn],a[maxn],b[maxn];
int award[maxn],atk[maxn];
ll qmul(ll a,ll b,ll mod){
    ll ans=0;
    for(;b;b>>=1,a=(a+a)%mod) if(b&1) ans=(ans+a)%mod;
    return ans;
}
ll exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return a;}
    ll d=exgcd(b,a%b,y,x);y-=a/b*x;return d;
}
ll gcd(ll a,ll b){
    if(!b) return a;
    return gcd(b,a%b);
}
int main(){
    scanf("%d",&t);
    while(t--){
        spec=false;same=exist=true;
        mts.clear();
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++) scanf("%lld",hp+i);
        for(int i=1;i<=n;i++){scanf("%lld",rec+i);if(rec[i]<hp[i]) spec=true;}
        for(int i=1;i<=n;i++) scanf("%d",award+i);
        for(int i=1;i<=m;i++){
            int x;
            scanf("%d",&x);
            mts.insert(x);
        }
        for(int i=1;i<=n;i++){
            multiset<ll>::iterator it;
            if(hp[i]<*mts.begin()) it=mts.begin();
            else it=mts.upper_bound(hp[i]),it--;
            atk[i]=*it;
            mts.erase(it);
            mts.insert(award[i]);
        }
        if(spec){
            ll ans=0;
            for(int i=1;i<=n;i++) ans=max(ans,ll(ceil(1.0*hp[i]/atk[i])));
            printf("%lld\n",ans);
            continue;
        }
        for(int i=1;i<=n;i++){
            if(!atk[i]){
                if(hp[i]==rec[i]){a[i]=0;b[i]=1;continue;}
                else{puts("-1");exist=false;break;}
            }
            if(hp[i]!=rec[i]) same=false;
            ll x,y,d=exgcd(atk[i],rec[i],x,y);
            if(hp[i]%d){puts("-1");exist=false;break;}
            x=(x+rec[i])%rec[i];b[i]=rec[i]/d;a[i]=qmul(x,hp[i]/d,b[i]);
        }
        if(same){
            ll ans=ll(ceil(1.0*hp[1]/atk[1]));
            for(int i=2;i<=n;i++){
                ll x=ceil(1.0*hp[i]/atk[i]),d=gcd(ans,x);
                ans=ans/d*x;
            }
            printf("%lld\n",ans);continue;
        }
        if(!exist) continue;
        ll ans=a[1],mod=b[1];
        for(int i=2;i<=n;i++){
            ll x,y,d=exgcd(mod,b[i],x,y),r=((a[i]-ans)%b[i]+b[i])%b[i],tmp=mod/d*b[i];
            if(r%d){puts("-1");exist=false;break;}
            x=(x+b[i])%b[i];x=qmul(x,r/d,b[i]);
            ans=(qmul(mod,x,tmp)+ans)%tmp;
            mod=tmp;
        }
        if(!exist) continue;
        printf("%lld\n",ans);
    }
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #146.921 ms2 MB + 324 KBAcceptedScore: 5

Testcase #246.64 ms2 MB + 324 KBAcceptedScore: 5

Testcase #348.77 ms2 MB + 324 KBAcceptedScore: 5

Testcase #448.435 ms2 MB + 324 KBAcceptedScore: 5

Testcase #52.557 ms140 KBAcceptedScore: 5

Testcase #62.517 ms140 KBAcceptedScore: 5

Testcase #72.562 ms140 KBAcceptedScore: 5

Testcase #819.61 us52 KBAcceptedScore: 5

Testcase #919.51 us52 KBAcceptedScore: 5

Testcase #1018.69 us52 KBAcceptedScore: 5

Testcase #1118.29 us52 KBAcceptedScore: 5

Testcase #1219.11 us52 KBAcceptedScore: 5

Testcase #1319.78 us52 KBAcceptedScore: 5

Testcase #14270.216 ms6 MB + 916 KBAcceptedScore: 5

Testcase #15270.749 ms6 MB + 916 KBAcceptedScore: 5

Testcase #16538.909 ms8 MB + 428 KBAcceptedScore: 5

Testcase #17537.969 ms8 MB + 428 KBAcceptedScore: 5

Testcase #18560.902 ms8 MB + 428 KBAcceptedScore: 5

Testcase #19559.637 ms8 MB + 428 KBAcceptedScore: 5

Testcase #20556.668 ms8 MB + 428 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 09:42:48 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠