提交记录 4431


用户 题目 状态 得分 用时 内存 语言 代码长度
ghostfly233 noi18d. 【NOI2018】屠龙勇士 Accepted 100 519.544 ms 8640 KB C++ 1.95 KB
提交时间 评测时间
2018-07-22 21:49:43 2020-07-31 23:01:30
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define MN 500005
using namespace std;
typedef long long ll;
int n,m,T;ll lif[MN],hea[MN],atk[MN],afatk[MN],patk[MN];
multiset<ll>st;
multiset<ll>::iterator it;
void add(ll &x,ll y,ll mod){(x+=y)>=mod?x-=mod:0;}
ll mul(ll x,ll y,ll mod){
	ll tmp=0;
	while(y){
		if(y&1)add(tmp,x,mod);
		add(x,x,mod);y>>=1;
	}return tmp;
}
ll exgcd(ll a,ll b,ll &x,ll &y){
	if(!b){x=1,y=0;return a;}
	ll d=exgcd(b,a%b,x,y),tmp=x;x=y,y=tmp-a/b*x;
	return d;
}
int main(){
	freopen("dragon19.in","r",stdin);
	freopen("dragon.out","w",stdout);
	scanf("%d",&T);ll x,y;
	while(T--){
		scanf("%d%d",&n,&m);st.clear();bool fd=1;
		for(int i=1;i<=n;i++)scanf("%lld",&lif[i]);
		for(int i=1;i<=n;i++)scanf("%lld",&hea[i]),fd&=(hea[i]==1);
		for(int i=1;i<=n;i++)scanf("%lld",&afatk[i]);
		for(int i=1;i<=m;i++)scanf("%lld",&patk[i]),st.insert(patk[i]);
		for(int i=1;i<=n;i++){
			it=st.upper_bound(lif[i]);if(it!=st.begin())--it;
			atk[i]=(*it);st.erase(it);st.insert(afatk[i]);
		}
		if(fd){
			ll ans=0; 
			for(int i=1;i<=n;i++)ans=max(ans,(lif[i]-1)/atk[i]+1);
			printf("%lld\n",ans);
		}else {
			bool OK=1;
			for(int i=1;i<=n;i++){//atk[i]*x=lif[i] (mod hea[i])
				atk[i]%=hea[i],lif[i]%=hea[i];
				ll tmp=exgcd(atk[i],hea[i],x,y);
				atk[i]/=tmp,hea[i]/=tmp;
				if(lif[i]%tmp){OK=0;break;}
				lif[i]/=tmp;x=(x%hea[i]+hea[i])%hea[i];
				lif[i]=mul(lif[i],x,hea[i]);
			}if(!OK){puts("-1");continue;}ll ansl=0,ansp=1;
			for(int i=1;i<=n;i++){//x=ansl (mod ansp),x=lif[i] (mod hea[i]) --> ansp*k1+ansl=hea[i]*k2+lif[i] -->ansp*x-hea[i]*y=lif[i]-ansl 
				ll c=lif[i]-ansl;int f=c<0?-1:1;c=abs(c);
				ll tmp=exgcd(ansp,hea[i],x,y);
				if(c%tmp){OK=0;break;}x=(x%hea[i]+hea[i])%hea[i],x=f*mul(x,c/tmp,hea[i]);x=(x%hea[i]+hea[i])%hea[i];
				ansl=(mul(x,ansp,ansp/tmp*hea[i])+ansl)%(ansp/tmp*hea[i]),ansp*=hea[i]/tmp;//printf("%lld %lld\n",ansl,ansp);
			}if(!OK)puts("-1");else printf("%lld\n",ansl?ansl:ansp);
		}
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #150.044 ms3 MB + 100 KBAcceptedScore: 5

Testcase #249.713 ms3 MB + 100 KBAcceptedScore: 5

Testcase #352.797 ms3 MB + 100 KBAcceptedScore: 5

Testcase #452.433 ms3 MB + 100 KBAcceptedScore: 5

Testcase #52.602 ms132 KBAcceptedScore: 5

Testcase #62.57 ms132 KBAcceptedScore: 5

Testcase #72.563 ms132 KBAcceptedScore: 5

Testcase #820.21 us44 KBAcceptedScore: 5

Testcase #920.09 us44 KBAcceptedScore: 5

Testcase #1018.88 us44 KBAcceptedScore: 5

Testcase #1118.65 us44 KBAcceptedScore: 5

Testcase #1218.91 us44 KBAcceptedScore: 5

Testcase #1321.06 us44 KBAcceptedScore: 5

Testcase #14269.76 ms8 MB + 448 KBAcceptedScore: 5

Testcase #15271.036 ms8 MB + 448 KBAcceptedScore: 5

Testcase #16510.764 ms8 MB + 448 KBAcceptedScore: 5

Testcase #17512.842 ms8 MB + 448 KBAcceptedScore: 5

Testcase #18519.166 ms8 MB + 448 KBAcceptedScore: 5

Testcase #19519.544 ms8 MB + 448 KBAcceptedScore: 5

Testcase #20517.981 ms8 MB + 448 KBAcceptedScore: 5


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