QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106848#6399. Classic: Classical Problemwhatever#WA 3ms5744kbC++173.0kb2023-05-19 15:34:102023-05-19 15:34:12

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-19 15:34:12]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 5744kb
  • [2023-05-19 15:34:10]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(y<x)x=y;}

#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define mem(x) memset((x),0,sizeof(x))

typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;

typedef unsigned u32;
typedef unsigned uint;
typedef unsigned long long u64;

namespace orzjk{
  const int SZ=1e6;
  char buf[SZ],*p1=buf,*p2=buf;
  char nc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
  }
  char fub[SZ],*p3=fub,*p4=fub+SZ;
  void pc(char c){
    p3==p4&&(fwrite(fub,1,SZ,stdout),p3=fub);
    *p3++=c;
  }
  void flush(){
    fwrite(fub,1,p3-fub,stdout),p3=fub;
  }
}
using orzjk::nc;
using orzjk::pc;

//#define nc getchar
//#define pc putchar

int read(){
  int x=0,f=1;char c=nc();
  while(c<48)c=='-'&&(f=-1),c=nc();
  while(c>47)x=x*10+(c^48),c=nc();
  return x*f;
}
template<class T>void write(T x){
  static char st[41];
  if(!x)return pc(48),void();
  char*p=st;
  if(x<0)x=-x,pc('-');
  for(;x;x/=10)*p++=x%10|48;
  do{
    pc(*--p);
  }while(p!=st);
}

const int maxn=2e5+10;

ll qpow(ll a, ll b, ll p) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % p;
    a = a * a % p, b >>= 1;
  }
  return res;
}

ll generator(ll p) {
  vector<ll> fact;
  ll phi = p - 1, n = phi;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      fact.push_back(i);
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) fact.push_back(n);
  for (ll res = 2; res <= p; ++res) {
    bool ok = true;
    for (ll factor : fact) {
      if (qpow(res, phi / factor, p) == 1) {
        ok = false;
        break;
      }
    }
    if (ok) return res;
  }
  return -1;
}



void solve(){
  int s=read(),p=read();
  int g=generator(p);
  
  static int pw[maxn],mp[maxn];
  pw[0]=1,mp[1]=0;
  rep(i,1,p-2)pw[i]=1ll*pw[i-1]*g%p,mp[pw[i]]=i;
  
  static bitset<maxn>cur,as;
  cur.reset(),as.reset();
  
  bool f0=0;
  rep(i,1,s){
    int x=read();
    if(!x){
      f0=1;
    }else{
      cur.set(mp[x]);
    }
  }
  if(!f0){
    puts("1 1\n0");return;
  }
  
  int mx=0;vi vec;
  rep(i,0,p-2){
    if((cur&as)==as){
      bool flg=0;
      while(mx<s-1&&cur[mp[mx+1]]){
        as.set(mp[mx+1]);
        mx++,flg=1;
      }
      if(flg)vec.clear();
      vec.pb(pw[i]);
    }
    
    cur<<=1;
    if(cur.test(p-1)){
      cur.flip(p-1);
      cur.flip(0);
    }
  }
  printf("%d %d\n",(int)vec.size(),mx+1);
  sort(ALL(vec));
  for(int x:vec)printf("%d ",x);
  puts("");
}

signed main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
  int T;cin>>T;while(T--)solve();
//  solve();
  orzjk::flush();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3708kb

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

input:

3
1 2
0
1 2
1
2 2
1 0

output:

1 1
1 
1 1
0
1 2
1 

result:

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