QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569261 | #4888. Decoding The Message | Made_in_Code | RE | 6ms | 3816kb | C++14 | 2.5kb | 2024-09-16 21:33:13 | 2024-09-16 21:33:13 |
Judging History
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 <= m; 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: 0ms
memory: 3536kb
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: 6ms
memory: 3816kb
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...