QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105565#6399. Classic: Classical Problemwoyouxiangbaile#WA 2ms3668kbC++142.4kb2023-05-14 13:39:542023-05-14 13:39:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-14 13:39:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3668kb
  • [2023-05-14 13:39:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

const int N = 2e5 + 10;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int P;

int inc(int a, int b) { return (a += b) >= P ? a - P : a; }
int dec(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
void add(int &a, int b) { (a += b) >= P ? a -= P : 1; }
void sub(int &a, int b) { (a -= b) < 0 ? a += P : 1; }
int sgn(int x) { return x & 1 ? P - 1 : 1; }
int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }

int n, g, a[N], id[N], dat[N], ans;
vector <int> all;
bitset <N> s, o;

void solve() {
  n = read(), P = read();
  rep(i, 1, n) a[i] = read();
  if (*min_element(a + 1, a + n + 1)) {
    printf("1 1\n0\n");
    return;
  }
  for (g = 2; g < P; ++ g) {
    auto chk = [&]() {
      for (int i = 1, val = g; i < P - 1; ++ i) {
        if (val == 1) return false;
        val = mul(val, g);
      }
      return true;
    } ;
    if (chk()) break;
  }
  fill(id, id + P, 0), dat[0] = 1;
  for (int i = 1, val = g; i < P - 1; ++ i) {
    id[val] = i, dat[i] = val;
    val = mul(val, g);
  }
  s.reset(), o.reset();
  rep(i, 1, n) if (a[i]) s[id[a[i]]] = 1;
  ans = 0, all.clear();
  rep(i, 0, P - 2) {
    if ((s & o) == o) {
      int cur = ans;
      while (true) {
        if (++ cur == P) break;
        o[id[cur]] = 1;
        if ((s & o) != o) break;
      }
      if (cur < P) o[id[cur]] = 0;
      -- cur;
      if (cur > ans) {
        ans = cur;
        all.clear();
        all.emplace_back(dat[i]);
      }
      else if (cur == ans) {
        all.emplace_back(dat[i]);
      }
    }
    s <<= 1;
    s[0] = s[P - 1], s[P - 1] = 0;
  }
  sort(all.begin(), all.end());
  printf("%d %d\n", (int) all.size(), ans + 1);
  for (auto it : all) printf("%d ", it);
  printf("\n");
}

int main() {
  for (int tc = read(); tc; -- tc) solve();
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3668kb

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: 2ms
memory: 3616kb

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'