QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202053#6399. Classic: Classical Problemucup-team870#WA 1ms3440kbC++141.8kb2023-10-05 18:50:472023-10-05 18:50:47

Judging History

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

  • [2023-10-05 18:50:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3440kb
  • [2023-10-05 18:50:47]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
typedef long long ll;
int p;
int ksm(ll x,int y){
    ll ans=1;
    while(y){
        if (y&1) ans=ans*x%p;
        x=x*x%p; y>>=1;
    }
    return ans;
}
vector<int> no,an;
bool fl[300005];
int main(){
    IOS
    int _; cin>>_;
    while(_--){
        int n,x; cin>>n>>p;
        For(i,1,n) cin>>x,fl[x]=1;
        if (!fl[0]) {cout<<"1 1\n0\n"; goto E;}
        if (n==p){
            cout<<n<<' '<<n<<'\n';
            For(i,0,n-1) cout<<i<<' '; cout<<'\n'; goto E;
        }
        //small
        if (p-n<=1500){
            For(i,1,p-1) if (!fl[i]) no.push_back(i);
            ll ma=0;
            For(c,1,p-1){ //cout<<'!'<<c<<endl;
                ll mi=p;
                for(auto k:no) mi=min(mi,1ll*c*k%p); //cout<<k<<' '<<1ll*c*k%p<<endl;
                if (mi==ma) an.push_back(c);
                else if (mi>ma) ma=mi,an.clear(),an.push_back(c);
            }
            cout<<an.size()<<' '<<ma<<'\n';
            for(auto y:an) cout<<y<<' '; cout<<'\n';
        }
        else{
            ll ma=0;
            For(c,1,p-1){
                ll nc=ksm(c,p-2);
                For(a,1,p-1){
                    int x=nc*a%p;
                    if (!fl[x]){
                        if (a==ma) an.push_back(c);
                        else if (a>ma) ma=a,an.clear(),an.push_back(c);
                        break;
                    }
                }
            }
            cout<<an.size()<<' '<<ma<<'\n';
            for(auto y:an) cout<<y<<' '; cout<<'\n';
        }
        //clear
        E:;
        an.clear(); no.clear();
        For(i,0,p-1) fl[i]=0;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3400kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

1 1
1 
1 1
0
2 2
0 1 

result:

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