QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573273 | #4888. Decoding The Message | hhoppitree | WA | 9ms | 5908kb | C++17 | 2.9kb | 2024-09-18 17:58:50 | 2024-09-18 17:58:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 256;
int c[N], d[4];
int ksm(int x, int y, int P) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % P;
x = 1ll * x * x % P;
y >>= 1;
}
return res;
}
int solve(int mod) {
int s = 0, n = 0;
for (int i = 0; i < N; ++i) s += c[i] * i, n += c[i];
s %= mod;
if (!s) return 0;
int fac = 1;
for (int i = 1; i <= n && fac; ++i) fac = fac * i % (mod - 1);
return ksm(s % mod, fac, mod);
}
int dp[1 << 11][257];
bitset<257> f[605], g[605];
int calc() {
int n = 0, mx = 0;
for (int i = 0; i < N; ++i) n += c[i], mx = max(mx, c[i]);
if (n <= 11) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
vector<int> o;
for (int i = 0; i < N; ++i) {
for (int j = 1; j <= c[i]; ++j) o.push_back(i);
}
for (int i = 1; i < 1 << n; ++i) {
int od = __builtin_parity(i);
for (int j = 0; j < n; ++j) {
if ((i >> j) & 1) {
for (int k = 0; k < 257; ++k) {
int nw = (od ? k - o[j] + 257: k + o[j]) % 257;
dp[i][k] += dp[i ^ (1 << j)][nw];
}
}
}
}
int res = 1;
for (int i = 0; i < 257; ++i) res = 1ll * res * ksm(i, dp[(1 << n) - 1][i], 257) % 257;
return res;
}
if (n - mx > 600) return 0;
for (int i = 0; i < 605; ++i) f[i].reset();
f[0][0] = 1;
vector<int> o;
int tmx;
for (int i = 0; i < N; ++i) if (c[i] == mx) tmx = i;
for (int i = 0; i < N; ++i) {
if (i != tmx) for (int j = 1; j <= c[i]; ++j) o.push_back(i);
}
for (int i = 0; i < (int)o.size(); ++i) {
int x = o[i];
for (int j = 0; j <= i; ++j) {
g[j] |= f[j] << x;
g[j] |= f[j] >> (257 - x);
x = (257 - x) % 257;
g[j + 1] |= f[j] << x;
g[j + 1] |= f[j] >> (257 - x);
x = (257 - x) % 257;
}
for (int j = 0; j <= i + 1; ++j) f[j] = g[j];
}
for (int i = 0; i <= mx && i <= n / 2; ++i) {
for (int j = 0; j < 257; ++j) {
if (f[n / 2 - i][j] && (j + (mx - i) * tmx + i * (257 - tmx)) % 257 == 0) return 1;
}
}
return 0;
}
signed main() {
int T; scanf("%d", &T);
while (T--) {
int n; scanf("%d", &n);
fill(c, c + 256, 0);
for (int i = 1, x, y; i <= n; ++i) scanf("%d%d", &x, &y), c[x] += y;
d[0] = solve(3), d[1] = solve(5), d[2] = solve(17), d[3] = calc();
for (int i = 0; ; ++i) {
if (i % 3 == d[0] && i % 5 == d[1] && i % 17 == d[2] && i % 257 == d[3]) {
printf("%d\n", i);
break;
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5904kb
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: 9ms
memory: 5908kb
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 26215 32896 39321 15420 26215 43570 1 48060 32640 26215 39321 59110 50116 48060 48060 54741 54741 1 48060 26215 54741 21846 32896 15420 15420 1 17476 59110 1 48060 21846 39321 50116 48060 54741 21846 6426 21846 21846 39321 21846 32896 26215 26215 59110 21846 15420 48060 22101 59110...
result:
wrong answer 1st numbers differ - expected: '21846', found: '54741'