QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#680857#5301. Modulo Ruins the LegendwzxtslWA 0ms3692kbC++231.5kb2024-10-26 23:07:032024-10-26 23:07:04

Judging History

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

  • [2024-10-26 23:07:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3692kb
  • [2024-10-26 23:07:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e6+7;
int n,m,sum,x,t;
int exgcd(int a,int b,int c,int &x,int &y){
	if(!b) return x=c/a,y=0,a;
	int res=exgcd(b,a%b,c,y,x);
	return y-=a/b*x,res;
}
int jie(int a,int b,int c){
	int x,y,d=exgcd(a,b,c,x,y);
	if(c%d==0) return (x%(b/d)+b/d)%(b/d);
	return -1;
}
void solve(){
	cin>>n>>m;
	For(i,1,n)
	{
		cin>>x,sum+=x;
	}
	int g;
	if(n&1)
	{
		g=__gcd(n,m);
		if(g==1) t=0;
		else{
			t=sum%g;
		}
		/*n=n/g,m=m/g;
		cout<<t<<endl;
		int d=0;
		int s=((t-sum)/g*jie(n,m,1)%m+m)%m;
		cout<<s<<" "<<d;*/
	}
	else{
		g=__gcd(n/2,m);
		if(g==1) t=0;
		else{
			t=sum%g;
		}
		/*cout<<t<<endl;
		int tp=n;	
		n=n/2/g,m=m/g;	
		int tot=(t-sum)/g*jie(n,m,1),d,s;
		if(tot&1) d=1,s=(((t-sum)/g*jie(n,m,1)-tp-1)/2%m+m)%m;
		else d=0,s=(((t-sum)/g*jie(n,m,1))/2%m+m)%m;
		cout<<s<<" "<<d;*/
	}
	cout<<t<<endl;
	t=((t-sum)%m+m)%m;
	while(t<=n*(n+1)/2) t+=m;
	int d,s;
	exgcd(n,n*(n+1)/2,t,s,d);
	//exgcd(6,21,33,s,d);
	d=(d%m+m)%m;
	s=(s%m+m)%m;
cout<<s<<" "<<d;

}
signed main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

6 24
1 1 4 5 1 4

output:

1
15 11

result:

ok ok

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3596kb

input:

7 29
1 9 1 9 8 1 0

output:

0
4 0

result:

wrong answer Result not equal to solution.