QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573342 | #4888. Decoding The Message | hhoppitree | RE | 9ms | 5928kb | C++17 | 2.9kb | 2024-09-18 18:17:02 | 2024-09-18 18:17:02 |
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 0;
}
}
return 1;
}
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: 0ms
memory: 5880kb
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: 0
Accepted
time: 9ms
memory: 5928kb
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:
21846 21846 26215 59110 32896 6426 48060 59110 43570 32896 15420 0 59110 6426 26215 17476 15420 15420 21846 21846 32896 15420 59110 21846 54741 32896 48060 48060 32896 50116 26215 32896 15420 54741 6426 17476 15420 21846 54741 39321 54741 54741 6426 54741 1 59110 59110 26215 54741 15420 15420 22101 ...
result:
ok 100 numbers
Test #3:
score: -100
Runtime Error
input:
100 1 208 74003161 1 108 37880052 1 102 289342450 1 190 16254190 1 20 507132853 1 1 842472902 1 212 226854721 1 33 797732105 1 213 114087750 1 128 914592259 1 27 779924279 1 203 425018504 1 217 458915584 1 139 710603120 1 226 84538604 1 50 602470204 1 150 228443262 1 48 593328022 1 24 35949157 1 148...