QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627166#5301. Modulo Ruins the LegenddjwcbRE 1ms5748kbC++232.1kb2024-10-10 15:03:232024-10-10 15:03:30

Judging History

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

  • [2024-10-10 15:03:30]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5748kb
  • [2024-10-10 15:03:23]
  • 提交

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;
    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];
    }
    int all=cacu();
    sum%=mod;
  //  cout<<sum<<endl;
    int now=mod-sum;
    for(int i=0;i<=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);
//        cout<<"-----------"<<endl;
        if(k%d==0){
            x=x*k/d;
            y=(k-a*x)/b;
           // cout<<x<<" "<<y<<endl;
            x%=mod;
            y%=mod;
            int ans1=0,ans2=0;
            if(x<0){
                int v=x*n;
              //  cout<<x<<" "<<y<<" "<<v<<endl;
                int tv=mod+v%mod;
                int o=0,oo=0;
               // cout<<tv<<endl;
                int p=exgcd(a,mod,o,oo)%mod;
//                cout<<o<<" "<<oo<<endl;
                o*=tv/p;
                oo=(tv-a*oo)/mod;
                ans1=o;
                ans2=y;
            }
            if(y<0){
                int v=y*all;
                int tv=mod+v%mod;
                int o=0,oo=0;
                int p=exgcd(all,mod,o,oo)%mod;
                o*=tv/p;
                oo=(tv-a*oo)/mod;
                ans1=x;
                ans2=oo;
            }
            cout<<i<<endl;
            cout<<ans1<<" "<<ans2<<endl;
            return ;
        }
    }


}
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: 100
Accepted
time: 1ms
memory: 5612kb

input:

6 24
1 1 4 5 1 4

output:

1
3 3

result:

ok ok

Test #2:

score: 0
Accepted
time: 1ms
memory: 5748kb

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

score: -100
Runtime Error

input:

1 1
0

output:


result: