提交记录 4429


用户 题目 状态 得分 用时 内存 语言 代码长度
ghostfly233 noi18d. 【NOI2018】屠龙勇士 Time Limit Exceeded 85 2 s 7080 KB C++ 1.92 KB
提交时间 评测时间
2018-07-22 21:38:28 2020-07-31 23:01:20
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define MN 500005
using namespace std;
typedef long long ll;
int n,m,T,hea[MN],atk[MN],afatk[MN],patk[MN];ll lif[MN];
multiset<int>st;
multiset<int>::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("%d",&hea[i]),fd&=(hea[i]==1);
		for(int i=1;i<=n;i++)scanf("%d",&afatk[i]);
		for(int i=1;i<=m;i++)scanf("%d",&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 #148.373 ms1 MB + 976 KBAcceptedScore: 5

Testcase #247.987 ms1 MB + 976 KBAcceptedScore: 5

Testcase #351.205 ms1 MB + 976 KBAcceptedScore: 5

Testcase #450.911 ms1 MB + 976 KBAcceptedScore: 5

Testcase #52.516 ms120 KBAcceptedScore: 5

Testcase #62.478 ms120 KBAcceptedScore: 5

Testcase #72.47 ms120 KBAcceptedScore: 5

Testcase #823.2 us48 KBAcceptedScore: 5

Testcase #919.48 us48 KBAcceptedScore: 5

Testcase #1019.21 us48 KBAcceptedScore: 5

Testcase #1118.14 us48 KBAcceptedScore: 5

Testcase #1218.2 us48 KBAcceptedScore: 5

Testcase #1320.1 us48 KBAcceptedScore: 5

Testcase #14269.325 ms6 MB + 936 KBAcceptedScore: 5

Testcase #15269.518 ms6 MB + 936 KBAcceptedScore: 5

Testcase #16496.364 ms6 MB + 936 KBAcceptedScore: 5

Testcase #17497.767 ms6 MB + 936 KBAcceptedScore: 5

Testcase #182 s6 MB + 932 KBTime Limit ExceededScore: 0

Testcase #192 s6 MB + 932 KBTime Limit ExceededScore: 0

Testcase #202 s6 MB + 932 KBTime Limit ExceededScore: 0


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