QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#516722#6399. Classic: Classical Problemwangyue2017WA 1ms5804kbC++201.9kb2024-08-12 20:52:302024-08-12 20:52:31

Judging History

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

  • [2024-08-12 20:52:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5804kb
  • [2024-08-12 20:52:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define g(x) scanf("%lld",&x)
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;
    g(n);g(p);
    int k=n-p;
    bool flag=0;
    
    for(int i=1;i<=n;++i)g(s[i]),exi[s[i]]=1,flag|=(s[i]==0);
    
    if(flag==0){
        cout<<"1 1\n0\n";
    }
    else if(n==1&&s[1]==0){
        printf("%lld %lld\n",p,1ll);
        for(int i=0;i<p;++i)printf("%lld ",i);
        putchar('\n');
    }
    else if(n==p){

        printf("%lld %lld\n",n-1,p);
        for(int i=0;i<p;++i)printf("%lld ",i);
        putchar('\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);
        }

        printf("%lld %lld\n",ans.size()-1,ans[0]);
        ans.erase(ans.begin());
        for(int i:ans)printf("%lld ",i);
        putchar('\n');
    }
    else{
        ans.push_back(-1);
        for(int c=1;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);
        }
        
        printf("%lld %lld\n",ans.size()-1,ans[0]);
        ans.erase(ans.begin());
        for(int i:ans)printf("%lld ",i);
        putchar('\n');
    }
    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: 5804kb

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: 0ms
memory: 3796kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1 
1 1
0
1 2
0 1 

result:

wrong answer 6th lines differ - expected: '1', found: '0 1 '