提交记录 4430


用户 题目 状态 得分 用时 内存 语言 代码长度
ghostfly233 noi18d. 【NOI2018】屠龙勇士 Wrong Answer 90 515.398 ms 8640 KB C++ 1.93 KB
提交时间 评测时间
2018-07-22 21:40:11 2020-07-31 23:01:24
#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("dragon.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;continue;}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.388 ms3 MB + 100 KBAcceptedScore: 5

Testcase #250.041 ms3 MB + 100 KBAcceptedScore: 5

Testcase #353.368 ms3 MB + 100 KBAcceptedScore: 5

Testcase #452.96 ms3 MB + 100 KBAcceptedScore: 5

Testcase #52.556 ms132 KBAcceptedScore: 5

Testcase #62.517 ms132 KBAcceptedScore: 5

Testcase #72.508 ms132 KBAcceptedScore: 5

Testcase #823.35 us44 KBAcceptedScore: 5

Testcase #919.78 us44 KBAcceptedScore: 5

Testcase #1019.23 us44 KBAcceptedScore: 5

Testcase #1117.59 us44 KBAcceptedScore: 5

Testcase #1218.33 us44 KBAcceptedScore: 5

Testcase #1318.93 us44 KBAcceptedScore: 5

Testcase #14270.731 ms8 MB + 448 KBAcceptedScore: 5

Testcase #15271.204 ms8 MB + 448 KBAcceptedScore: 5

Testcase #16504.983 ms8 MB + 448 KBAcceptedScore: 5

Testcase #17506.08 ms8 MB + 448 KBAcceptedScore: 5

Testcase #18515.398 ms8 MB + 448 KBAcceptedScore: 5

Testcase #19510.557 ms8 MB + 448 KBWrong AnswerScore: 0

Testcase #20509.755 ms8 MB + 448 KBWrong AnswerScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-13 14:27:58 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠