QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573140 | #4888. Decoding The Message | hhoppitree | WA | 8ms | 5864kb | C++17 | 1.9kb | 2024-09-18 17:30:23 | 2024-09-18 17:30:23 |
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];
int calc() {
int n = 0;
for (int i = 0; i < N; ++i) n += 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;
}
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: 2ms
memory: 5860kb
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: 8ms
memory: 5864kb
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 26215 32896 6426 48060 26215 43570 1 48060 32640 26215 6426 26215 50116 48060 48060 21846 21846 1 48060 26215 21846 21846 32896 48060 48060 1 50116 26215 1 48060 21846 6426 50116 48060 21846 21846 6426 21846 21846 6426 21846 1 26215 26215 26215 21846 15420 48060 22101 26215 26215 1...
result:
wrong answer 4th numbers differ - expected: '59110', found: '26215'