QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748101#5301. Modulo Ruins the Legendhnust_100team#WA 0ms3528kbC++171.9kb2024-11-14 19:19:582024-11-14 19:20:00

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 19:20:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2024-11-14 19:19:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e17;
void solve(){
	int n,m;cin>>n>>m;
	vector<int>a(n+1);
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(n%m==0){
		cout<<sum%m<<"\n";
		cout<<"0"<<" "<<"0"<<"\n";
		return;
	}
	sum=m-sum%m;
	int c1,c2;
	if(n%2!=0){
		n=n%m;
		int g=__gcd(n,m);
		int p=n/g,q=m/g;
		int x,y;
		for(int i=0;i<=n;i++){
			if((i*q+1)%p==0){
				x=(i*q+1)/p;
				break;
			}
		}
		int dis1=sum-(sum/g)*g,dis2=inf;
		x%=m;
		if(dis1<=dis2){
			cout<<dis1<<"\n";
			cout<<(x*((sum/g)%m))%m<<" "<<"0"<<"\n";
			return;
		}else{
			cout<<dis2<<"\n";
			cout<<((x*((sum/g)%m))%m+x)%m<<" "<<"0"<<"\n";
			return;
		}
	}else{
		int g=__gcd(n/2,m);
		int cnt1,cnt2;//n/2 : cnt1+cnt2;
		int km=m;
		km=km*((n+1)/km)+km;
		if(km%2==0){
			cnt2=1;
			cnt1=(km+1-n-1)/2;
		}else{
			cnt1=(km+1)/2;
			cnt2=0;
		}
//		cout<<cnt1<<" "<<cnt2<<" :"<<cnt1*n+cnt2*n*(n+1)/2<<" "<<(cnt1*n+cnt2*n*(n+1)/2)%m<<"\n";
		int p=(n/2)/g,q=m/g;
//		cout<<g<<" "<<p<<"*"<<q<<"\n";
		int x,y;
		for(int i=0;i<=n;i++){
//			cout<<(i*q+1)<<" "<<p<<"\n";
			if((i*q+1)%p==0){
				x=(i*q+1)/p;
				break;
			}
		}
//		cout<<x<<"\n";
		int dis1=sum-(sum/g)*g,dis2=inf;
//		cout<<cnt1<<" "<<cnt2<<" "<<x<<" "<<sum<<" "<<g<<"\n";
		cnt1%=m;cnt2%=m;x%=m;
		if(dis1<=dis2){
			cout<<dis1<<"\n";
		    c1=(cnt1*((x*((sum/g)%m)%m)%m))%m,c2=(cnt2*((x*((sum/g)%m)%m)%m))%m;
			cout<<c1<<" "<<c2<<"\n";
//			cout<<(m-sum+c1*n+c2*n*(n+1)/2)%m<<"\n";
			return;
		}else{
			cout<<dis2<<"\n";
			c1=(cnt1*(((x*((sum/g)%m)%m)%m+x)%m))%m,c2=(cnt2*(((x*((sum/g)%m))%m+x)%m))%m;
			cout<<c1<<" "<<c2<<"\n";
//			cout<<(m-sum+c1*n+c2*(n+1)*n/2)%m<<"\n";
			return;
		}
	}
}
signed  main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3528kb

input:

6 24
1 1 4 5 1 4

output:

2
18 2

result:

wrong answer Result not equal to solution.