QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569242#4888. Decoding The MessageMade_in_CodeWA 7ms3600kbC++142.5kb2024-09-16 21:27:382024-09-16 21:27:38

Judging History

This is the latest submission verdict.

  • [2024-09-16 21:27:38]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 3600kb
  • [2024-09-16 21:27:38]
  • Submitted

answer

#include <bitset>
#include <iostream>
#define LL long long

using namespace std;

int t, a[256];
LL n;

LL Pow(LL x, int y, int mod) {
  LL ans = 1;
  for (int i = 1; i <= y; i <<= 1) {
    if (i & y) {
      ans = ans * x % mod;
    }
    x = x * x % mod;
  }
  return ans;
}

LL Calc1() {
  LL ans = 0;
  for (int i = 0; i < 256; i++) {
    ans = (ans + 1LL * i * a[i]) % 255;
  }
  if (n >= 8) {
    ans = Pow(ans, 128, 255);
  } else {
    for (int i = 1; i <= n; i++) {
      ans = Pow(ans, i, 255);
    }
  }
  return ans;
}

LL Calc20() {
  int d[11] = {};
  for (int i = 0, t = 0; i < 256; i++) {
    for (int j = 1; j <= a[i]; j++) {
      d[t++] = i;
    }
  }
  LL t = 1;
  for (int s = 0; s < 1 << n; s++) {
    if (__builtin_popcount(s) == n >> 1) {
      LL w = 0;
      for (int i = 0; i < n; i++) {
        if (s >> i & 1) {
          w = (w - d[i] + 257) % 257;
        } else {
          w = (w + d[i]) % 257;
        }
      }
      t = t * w % 257;
    }
  }
  for (int i = 1; i <= n >> 1; i++) {
    t = Pow(t, i * i, 257);
  }
  return n & 1 ? Pow(t, n + 1 >> 1, 257) : t;
}

LL Calc21() {
  int mx = 0, m = n >> 1;
  LL s = 0;
  bitset<257> f[256], g[256];
  for (int i = 1; i < 256; i++) {
    s = (s + 1LL * a[i] * i) % 257;
    if (a[i] > a[mx]) {
      mx = i;
    }
  }
  s = s * 129 % 257;
  for (int i = 0; i < 256; i++) {
    f[i].reset(), g[i].reset();
  }
  f[0][0] = g[0][0] = 1;
  for (int i = 0; i < 256; i++) {
    if (i != mx) {
      for (int j = 1; j <= m; j++) {
        for (int k = 0; k <= a[i]; k++) {
          int w = i * k % 257;
          g[j + k] |= f[j] << w | f[j] >> 257 - w;
        }
      }
      for (int j = 0; j <= m; j++) {
        f[j] = g[j];
      }
    }
  }
  for (int i = 0; i <= a[mx]; i++) {
    if (f[m - i][(s - i * mx % 257 + 257) % 257]) {
      return 0;
    }
  }
  return 1;
}

LL Calc2() {
  int mx = 0;
  for (int i = 0; i < 256; i++) {
    mx = max(mx, a[i]);
  }
  if (n >= 512 && n - mx >= 256) {
    return 0;
  } else if (n <= 11) {
    return Calc20();
  } else {
    return Calc21();
  }
}

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    n = 0;
    for (int i = 0; i < 256; i++) {
      a[i] = 0;
    }
    int m;
    cin >> m;
    for (int i = 1, x; i <= m; i++) {
      cin >> x >> a[x], n += a[x];
    }
    cout << (Calc1() * 32896 + Calc2() * 32640) % 65535 << '\n';  // CRT
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3600kb

input:

5
1
42 1
2
0 1
1 1
1
239 2
2
1 1
2 1
3
1 1
2 2
3 2

output:

42
256
514
1284
61726

result:

ok 5 number(s): "42 256 514 1284 61726"

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 3548kb

input:

100
1
213 79
1
54 69
1
218 55
1
248 80
1
101 8
1
153 79
1
240 45
1
112 70
1
217 5
1
208 64
1
48 30
1
0 19
1
53 40
1
63 17
1
179 65
1
221 22
1
135 84
1
138 20
1
54 29
1
114 19
1
253 94
1
240 36
1
40 94
1
244 93
1
239 24
1
133 8
1
105 91
1
45 43
1
241 74
1
206 17
1
100 73
1
133 44
1
57 70
1
56 72
1
47...

output:

54741
54741
59110
59110
32896
39321
15420
59110
43570
32896
15420
0
59110
39321
59110
17476
15420
15420
54741
54741
32896
15420
59110
54741
54741
32896
15420
15420
32896
50116
59110
32896
15420
54741
39321
17476
15420
54741
54741
39321
54741
54741
39321
54741
32896
59110
59110
59110
54741
15420
1542...

result:

wrong answer 1st numbers differ - expected: '21846', found: '54741'