QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152990 | #6399. Classic: Classical Problem | aesthetic | WA | 1ms | 3796kb | C++14 | 3.0kb | 2023-08-29 07:08:38 | 2023-08-29 07:08:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
typedef pair<int, int> pii;
const ll inf=LLONG_MAX;
const int maxn=1e5+10;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
int rand(int a, int b) {
return a + rng()%(b-a+1);
}
int modInv(int a, int m)
{
int m0=m;
int y=0, x=1;
if(m==1)
return 0;
while(a>1)
{
int q=a/m;
int t=m;
m=a%m, a=t;
t=y;
y=x-q*y;
x=t;
}
if(x<0)
x+=m0;
return x;
}
int n, p;
int mark[maxn];
int in[maxn];
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
int T; cin>> T;
while(T--)
{
cin>> n>> p;
for(int i=0; i<p; i++)
mark[i]=0;
vector<int> v;
for(int i=0; i<n; i++)
{
int ai; cin>> ai;
v.pb(ai);
mark[ai]=1;
}
if(!mark[0])
{
cout<< "1 1\n0\n";
continue;
}
if(n==p)
{
cout<< p<< " "<< p-1<< "\n";
for(int i=1; i<p; i++)
cout<< i<< " ";
cout<< "\n";
continue;
}
for(int i=1; i<p; i++)
in[i]=modInv(i, p);
shuffle(v.begin(), v.end(), rng);
// for(int x: v)
// cout<< x<< " ";
// cout<< "\n";
int best=-1;
int idmx=-1;
for(int i=0; i<n; i++)
{
int x=v[i];
if(!x)
continue;
// cout<< i<< " "<< x<< " "<< best<< "\n";
bool better=true;
int test=best+1;
while(test>=2)
{
if(mark[test*x%p])
test--;
else
{
better=false;
break;
}
}
if(better)
{
while(best+1<p && mark[(best+1)*x%p])
best++;
idmx=i;
}
}
vector<int> ans;
ans.pb(in[v[idmx]]);
for(int i=idmx+1; i<n; i++)
{
int x=v[i];
if(!x)
continue;
bool maximum=true;
int test=best;
while(test>=2)
{
if(mark[test*x%p])
test--;
else
{
maximum=false;
break;
}
}
if(maximum)
ans.pb(in[v[i]]);
}
cout<< ans.size()<< " "<< best+1<< "\n";
sort(ans.begin(), ans.end());
for(int x: ans)
cout<< x<< " ";
cout<< "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
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: 3764kb
input:
3 1 2 0 1 2 1 2 2 1 0
output:
1 0 0 1 1 0 2 1 1
result:
wrong answer 1st lines differ - expected: '2 1', found: '1 0'