QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#127814#6399. Classic: Classical ProblemUNos_mariconesWA 1ms3828kbC++202.6kb2023-07-20 09:00:112023-07-20 09:00:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 09:00:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2023-07-20 09:00:11]
  • 提交

answer

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

#define ff    first
#define ss    second
#define pb    push_back

typedef long long    ll;
typedef pair<ll,int>    ii;
typedef long double    lf;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll SQ = 320;
const ll N = 2e5+5;
const ll mod = 998244353;
const ll oo = 1e14+5;

int powmod (int a, int b, int p) {
    int res = 1;
    while (b)
        if (b & 1)
            res = int (res * 1ll * a % p),  --b;
        else
            a = int (a * 1ll * a % p),  b >>= 1;
    return res;
}

int generator (int p) {
    vector<int> fact;
    int phi = p-1,  n = phi;
    for (int 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 (int res=2; res<=p; ++res) {
        bool ok = true;
        for (size_t i=0; i<fact.size() && ok; ++i)
            ok &= powmod (res, phi / fact[i], p) != 1;
        if (ok)  return res;
    }
    return -1;
}


int main(){
  #ifdef LOCAL
  freopen("input.txt","r",stdin);
  #endif // LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int t; cin >> t;
  while (t--) {
    int n, p; cin >> n >> p;
    int c = generator(p);

    vector <int> a(n);
    vector <int> ap(p);
    for (auto &e : a) cin >> e, ap[e] = 1;
    sort(a.begin(), a.end());

    if (a[0] == 0) {
      if (n == 1) {
        cout << p << " 1\n";
        for (int i = 0; i < p; ++i) cout << i << ' ';
        cout << '\n';
      }
      else {
        vector <int> seq;
        int curre = 1;
        for (int i = 0; i < p - 1; ++i) seq.pb(curre), curre = (curre * c) % p;
        vector<bitset<N>> bt(p);
        bitset<N> up, down;
        for (int i = 0; i < p - 1; ++i) {
          if (ap[seq[i]]) down[p-i]=1;
        }
        for (int i = 0; i < p - 1; ++i) {
          up<<=1;
          down>>=1;
          if (ap[seq[i]]) {
            down[p-1]=0;
            up[0]=1;
          }
          bt[seq[i]] = up|down;
        }
        bitset<N> curr;
        curr.set();
        for (int i = 1; i <= p; ++i) {
          if (i<p&&(curr & bt[i]).any()) {
            curr &= bt[i];
          }
          else {
            cout << curr.count() << ' ' << i << '\n';
            for (int j = 0; j < p; ++j) {
              if (curr[j] == 1) cout << seq[j] << ' ';
            }
            cout << '\n';
            break;
          }
//          cout << i << endl;
        }
      }
    }
    else {
      cout << "1 1\n0\n";
    }
  }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
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: 0
Accepted
time: 1ms
memory: 3676kb

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

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
Wrong Answer
time: 1ms
memory: 3828kb

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
1 2
1 
1 1
0
1 2
3 
1 1
0
1 4
1 
1 1
0
1 2
2 
1 1
0
1 4
1 
1 1
0
2 2
2 3 
1 1
0
1 4
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
1 4
4 
1 1
0
2 5
1 4 
1 1
0
1 4
2 
1 1
0
1 5
1 
1 1
0
1 5
2 
1 1
0
3 5
1 2 4 

result:

wrong answer 13th lines differ - expected: '1 3', found: '1 4'