QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516711 | #6399. Classic: Classical Problem | wangyue2017 | TL | 1ms | 5732kb | C++20 | 1.9kb | 2024-08-12 20:43:53 | 2024-08-12 20:43:54 |
Judging History
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(n==1&&s[1]==0){
cout<<p<<" "<<1<<endl;
for(int i=0;i<p;++i)cout<<i<<" ";
cout<<endl;
}
else if(n==p){
cout<<n-1<<" "<<p<<endl;
for(int i=1;i<p;++i){
cout<<i<<" ";
}
cout<<endl;
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5732kb
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: 0
Accepted
time: 1ms
memory: 5672kb
input:
3 1 2 0 1 2 1 2 2 1 0
output:
2 1 0 1 1 1 0 1 2 1
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 5576kb
input:
7 1 3 0 1 3 1 2 3 1 0 1 3 2 2 3 2 0 2 3 1 2 3 3 0 1 2
output:
3 1 0 1 2 1 1 0 1 2 1 1 1 0 1 2 2 1 1 0 2 3 1 2
result:
ok 14 lines
Test #4:
score: -100
Time Limit Exceeded
input:
31 1 5 0 1 5 1 2 5 1 0 1 5 2 2 5 0 2 2 5 2 1 3 5 1 0 2 1 5 3 2 5 0 3 2 5 1 3 3 5 0 1 3 2 5 3 2 3 5 0 2 3 3 5 2 1 3 4 5 2 0 1 3 1 5 4 2 5 4 0 2 5 1 4 3 5 1 4 0 2 5 2 4 3 5 2 4 0 3 5 4 2 1 4 5 1 0 4 2 2 5 4 3 3 5 0 4 3 3 5 3 1 4 4 5 1 4 3 0 3 5 4 3 2 4 5 2 4 0 3 4 5 2 1 4 3 5 5 1 3 0 2 4
output:
5 1 0 1 2 3 4 1 1 0