QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#516681#6399. Classic: Classical Problemwangyue2017WA 1ms5724kbC++201.6kb2024-08-12 20:30:572024-08-12 20:30:58

Judging History

This is the latest submission verdict.

  • [2024-08-12 20:30:58]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5724kb
  • [2024-08-12 20:30:57]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N =2.1e5;
int s[N];
int exi[N];
vector<int>fp,ans;
int qmi(int x,int k,int p){
    int ans=1;
    while(k){
        if(k&1)ans=ans*x%p;
        x=x*x%p;
        k>>=1;
    }
    return ans;
}
void solve(){
    fp.clear();ans.clear();
    int n,p;
    cin>>n>>p;
    int k=n-p;
    bool flag=0;
    
    for(int i=1;i<=n;++i)cin>>s[i],exi[s[i]]=1,flag|=(s[i]==0);
    
    if(flag==0){
        cout<<"1 1\n0\n";
    }
    else if(k*k<=p){
        for(int i=1;i<p;++i){
            if(exi[i]==0)fp.push_back(i);
        }
        ans.push_back(-1);
        for(int c=0;c<p;++c){
            int mx=1e9;
            for(auto s:fp){
                mx=min(mx,s*c%p);
            }
            if(mx>ans[0])ans.clear(),ans.push_back(mx);
            if(mx==ans[0])ans.push_back(c);
        }
        cout<<ans.size()-1<<" "<<ans[0]<<endl;
        ans.erase(ans.begin());
        for(int u:ans){
            cout<<u<<" ";
        }
        cout<<endl;
    }
    else{
        ans.push_back(-1);
        for(int c=0;c<p;++c){
            int mx=1,rc=qmi(c,p-2,p);
            while(exi[mx*rc%p])mx++;
            if(mx>ans[0])ans.clear(),ans.push_back(mx);
            if(mx==ans[0])ans.push_back(mx);
        }
        cout<<ans.size()-1<<" "<<ans[0]<<endl;
        ans.erase(ans.begin());
        for(int u:ans){
            cout<<u<<" ";
        }
        cout<<endl;
    }
    for(int i=1;i<=n;++i){
        exi[s[i]]=0;
    }
}

signed main(){
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5668kb

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
2 
1 1
0
2 2
2 3 

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5724kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

1 1
1 
1 1
0
2 1000000000
0 1 

result:

wrong answer 1st lines differ - expected: '2 1', found: '1 1'