提交记录 5121


用户 题目 状态 得分 用时 内存 语言 代码长度
Infleaking noi18d. 【NOI2018】屠龙勇士 Accepted 100 827.382 ms 9404 KB C++ 1.65 KB
提交时间 评测时间
2018-08-07 11:31:58 2020-08-01 00:11:17
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
const int N=100100;
multiset<ll> s;
int n,m,T;
ll h[N],aw[N],atk[N],x;
ll a[N],b[N],p[N],Fail;
ll exgcd(ll a,ll b,ll &x,ll &y){
	if (b==0){x=1,y=0;return a;}
	ll x0,y0,ret=exgcd(b,a%b,x0,y0);
	x=y0,y=x0-(a/b)*y0;
	return ret;
}
ll gcd(ll a,ll b){
	if (b==0)return a;
	return gcd(b,a%b);
}
ll mul(ll a,ll b,ll mo){
	a=(a%mo+mo)%mo;b=(b%mo+mo)%mo;
	ll ans=0;
	while (b){
		if (b&1)ans=(ans+a)%mo;
		a=(a+a)%mo;
		b>>=1;
	}return ans;
}
void merge(int i,int j){
	ll b1=b[i],b2=b[j],p1=p[i],p2=p[j],k1,k2,g=gcd(p1,p2),L=(p1/g)*p2;
	if ((b2-b1)%g!=0){Fail=1;return;}
	exgcd(p1,p2,k1,k2);
	k1=mul(k1,(b2-b1)/g,L);
	b[i]=(b1+mul(k1,p1,L))%L,p[i]=L;
}
int main(){
for (scanf("%d",&T);T--;){
	scanf("%d%d",&n,&m);Fail=0;s.clear();
	for (int i=1;i<=n;i++)scanf("%lld",&h[i]);
	for (int i=1;i<=n;i++)scanf("%lld",&p[i]);
	for (int i=1;i<=n;i++)scanf("%lld",&aw[i]);
	for (int i=1;i<=m;i++)scanf("%lld",&x),s.insert(-x);
	for (int i=1;i<=n;i++){
		if (-(*--s.end())>h[i])atk[i]=-(*--s.end());
		else atk[i]=-(*s.lower_bound(-h[i]));
		s.erase(s.find(-atk[i]));
		a[i]=atk[i],b[i]=h[i];
		ll q=gcd(a[i],p[i]);
		if (b[i]%q!=0){Fail=1;break;}
		a[i]/=q,b[i]/=q,p[i]/=q;
		ll x,y;q=exgcd(a[i],p[i],x,y);
		x=(x%p[i]+p[i])%p[i];
		b[i]=mul(b[i],x,p[i]);
		s.insert(-aw[i]);
	}
	if (Fail){printf("-1\n");continue;}
	for (int i=2;i<=n;i++){
		merge(1,i);
		if (Fail)break;
	}
	if (Fail){printf("-1\n");continue;}
	ll ans=b[1],L=p[1];
	for (int i=1;i<=n;i++){
		ll al=(h[i]-1)/atk[i]+1;
		if (ans<al){
			ans=ans%L+(al/L)*L;
			while (ans-al>=L)ans-=L;
			while (ans<al)ans+=L;
		}
	}
	printf("%lld\n",ans);
}
return 0;}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1139.754 ms4 MB + 620 KBAcceptedScore: 5

Testcase #2139.616 ms4 MB + 620 KBAcceptedScore: 5

Testcase #3141.806 ms4 MB + 620 KBAcceptedScore: 5

Testcase #4141.427 ms4 MB + 620 KBAcceptedScore: 5

Testcase #54.861 ms144 KBAcceptedScore: 5

Testcase #64.809 ms144 KBAcceptedScore: 5

Testcase #74.812 ms144 KBAcceptedScore: 5

Testcase #821.15 us48 KBAcceptedScore: 5

Testcase #921.38 us48 KBAcceptedScore: 5

Testcase #1020.17 us48 KBAcceptedScore: 5

Testcase #1119.98 us48 KBAcceptedScore: 5

Testcase #1220.6 us48 KBAcceptedScore: 5

Testcase #1321.08 us48 KBAcceptedScore: 5

Testcase #14369.389 ms9 MB + 188 KBAcceptedScore: 5

Testcase #15370.365 ms9 MB + 188 KBAcceptedScore: 5

Testcase #16784.064 ms9 MB + 188 KBAcceptedScore: 5

Testcase #17793.745 ms9 MB + 188 KBAcceptedScore: 5

Testcase #18827.382 ms9 MB + 188 KBAcceptedScore: 5

Testcase #19823.38 ms9 MB + 188 KBAcceptedScore: 5

Testcase #20822.592 ms9 MB + 188 KBAcceptedScore: 5


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