提交记录 5113


用户 题目 状态 得分 用时 内存 语言 代码长度
Chuzyh noi18d. 【NOI2018】屠龙勇士 Accepted 100 687.093 ms 9840 KB C++ 2.25 KB
提交时间 评测时间
2018-08-06 19:54:48 2020-08-01 00:11:10
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100010;
int T,n,m,a[N],p[N],atk[N],be[N],each[N],x,y,re[N],mod[N];
map<int,int> mp;
map<int,int>::iterator it;
int Mul(int a,int b,int md)
{
    int res=0;a=(a%md+md)%md,b=(b%md+md)%md;
    while(b)
    {
        if(b&1)res=(res+a)%md;
        b>>=1,a<<=1,a%=md;
    }
    return res;
}
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ex_gcd(int a,int b,int &x,int &y)
{
    int d=a;
    if(!b)x=1,y=0;else d=ex_gcd(b,a%b,y,x),y-=(a/b)*x;
    return d;
}
int MLE(int *r,int *mod,int n)
{
    int lm=0,lb=1;
    for (int i=0;i<n;i++)
    {
        int k1,k2;
        int d=ex_gcd(lb, mod[i],k1,k2);
        if ((lm-r[i])%d)return -1;
        lb=lb/d*mod[i];
        int z=Mul(k2,((lm-r[i])/d),lb);	
        lm=Mul(z,mod[i],lb)+r[i],lm=((lm%lb)+lb)%lb;	
    }
    if(lm)return lm;else return lb;
}
signed main()
{
    scanf("%lld",&T);
    while(T--)
    {
        scanf("%lld%lld",&n,&m);mp.clear();int onlyone=1;
        for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
        for(int i=1;i<=n;i++)scanf("%lld",&p[i]),onlyone&=p[i]==1;
        for(int i=1;i<=n;i++)scanf("%lld",&atk[i]);
        for(int i=1;i<=m;i++)scanf("%lld",&be[i]),mp[be[i]]++;
        
        for(int i=1;i<=n;i++)
        {
            it=mp.begin();
            if((*it).first>a[i])
            {
                (*it).second--;each[i]=(*it).first;
                if((*it).second==0)mp.erase(it);
            }else
            {
                it=mp.upper_bound(a[i]);it--;
                (*it).second--;each[i]=(*it).first;
                if((*it).second==0)mp.erase(it);
            }
            mp[atk[i]]++;
        }
        int ans=1;
        if(onlyone)
        {
            ans=0;
            for(int i=1;i<=n;i++)ans=max(ans,(a[i]/each[i])+((a[i]%each[i])>0));
            printf("%lld\n",ans);continue;
        }
        for(int i=1;i<=n;i++)
        {
            int g=gcd(each[i],p[i]);
            each[i]/=g,p[i]/=g;
            if(a[i]%g){ans=0;break;}
            a[i]/=g;
            ex_gcd(each[i],p[i],x,y);int inv=x;
            re[i]=Mul(inv,a[i],p[i]);mod[i]=p[i];if(mod[i]==1)re[i]=1;
        }
        if(ans==0){puts("-1");continue;}
        ans=MLE(re+1,mod+1,n);
        printf("%lld\n",ans);
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #151.197 ms3 MB + 96 KBAcceptedScore: 5

Testcase #251.108 ms3 MB + 96 KBAcceptedScore: 5

Testcase #353.512 ms3 MB + 96 KBAcceptedScore: 5

Testcase #453.166 ms3 MB + 96 KBAcceptedScore: 5

Testcase #54.625 ms132 KBAcceptedScore: 5

Testcase #64.542 ms124 KBAcceptedScore: 5

Testcase #74.557 ms124 KBAcceptedScore: 5

Testcase #848.18 us64 KBAcceptedScore: 5

Testcase #948.87 us64 KBAcceptedScore: 5

Testcase #1046.75 us64 KBAcceptedScore: 5

Testcase #1147.55 us64 KBAcceptedScore: 5

Testcase #1247.12 us64 KBAcceptedScore: 5

Testcase #1348.94 us64 KBAcceptedScore: 5

Testcase #14287.802 ms9 MB + 624 KBAcceptedScore: 5

Testcase #15287.495 ms9 MB + 612 KBAcceptedScore: 5

Testcase #16649.027 ms5 MB + 384 KBAcceptedScore: 5

Testcase #17652.932 ms5 MB + 384 KBAcceptedScore: 5

Testcase #18687.093 ms5 MB + 384 KBAcceptedScore: 5

Testcase #19683.945 ms5 MB + 384 KBAcceptedScore: 5

Testcase #20682.458 ms5 MB + 384 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-05 21:19:46 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用