QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#627477 | #5301. Modulo Ruins the Legend | qilou | WA | 0ms | 5748kb | C++23 | 1.7kb | 2024-10-10 16:04:45 | 2024-10-10 16:04:45 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const int N=5e5+10,inf=1e9+10;
int n,m,k,sum=0,mod,ns[N];
int vis[N];
ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(!b)
{
x=1;y=0;
return a;
}
else
{
ll tx,ty;
ll d=exgcd(b,a%b,tx,ty);
x=ty;y=tx-(a/b)*ty;
return d;
}
}
int cacu(){
int res=0;
if(n==1){
return 1%mod;
}
int v=(1+n);
if(n%2==0){
res=v*n/2;
}else {
res=n/2*v+v/2;
}
return res%mod;
}
void solve(){
cin>>n>>mod;
for(int i=1;i<=n;i++){
cin>>ns[i];
sum+=ns[i];
}
if(mod==1){
cout<<0<<endl;
cout<<0<<" "<<0<<endl;
return ;
}
int all=cacu();
sum%=mod;
// cout<<sum<<endl;
int now=mod-sum;
for(int i=0;i<min(sum,n);i++){
int a=n,b=all,k=(now+i)%mod,x=0,y=0;
// cout<<a<<" "<<b<<endl;
int d=exgcd(a,b,x,y);
// if(mod==998244353){
// cout<<k<<" "<<d<<" "<<sum<<endl;
// }
// cout<<x<<" "<<y<<endl;
for(int j=1;j<=20;j++){
k=(now+i+j*mod);
if(k%d==0){
x=x*k/d;
y=(k-a*x)/b;
x=(x+mod)%mod;
y=(y+mod)%mod;
int ans1=x,ans2=y;
cout<<i<<endl;
cout<<ans1%mod<<" "<<ans2%mod<<endl;
return ;
}
}
}
cout<<sum<<endl;
cout<<0<<" "<<0<<endl;
}
signed main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T=1;
// cin>>T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5748kb
input:
6 24 1 1 4 5 1 4
output:
1 -9 11
result:
wrong answer Integer parameter [name=s] equals to -9, violates the range [0, 23]