QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#66635 | #5169. 夹娃娃 | 10circle | 0 | 2529ms | 34852kb | C++14 | 3.6kb | 2022-12-09 10:13:52 | 2022-12-09 10:13:53 |
Judging History
answer
// 哈哈,不认识“娃”这个字了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
int read() {
int a = 0, b = 0; char c = getchar();
while (c < '0' || c > '9') b ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') a = a * 10 - 48 + c, c = getchar();
return b ? -a : a;
}
const int N = 15, V = 1024, Vp = 521;
const int mod = 998244353, G = 3, iG = 332748118;
int n, q, f[N][V], vf[N][Vp][V];
void Add(int &a, int b) { if ((a += b) >= mod) a -= mod; }
void Sub(int &a, int b) { if ((a -= b) < 0) a += mod; }
int add(int a, int b) { return (a + b >= mod) ? a + b - mod : a + b; }
int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
void Fav(int &a, int b, int c) { a = (a + (ll)b * c) % mod; }
void Mul(int &a, int b) { a = (ll)a * b % mod; }
int mul(int a, int b) { return (ll)a * b % mod; }
int pw(ll a, int k) { ll s = 1; while (k) { if (k & 1) s = s * a % mod; a = a * a % mod; k >>= 1; } return s; }
int rv[V];
void init() {
for (int i = 1; i < V; ++i) rv[i] = (rv[i >> 1] >> 1) | ((i & 1) ? (V >> 1) : 0);
}
void NTT(int f[], int ag = 1) {
for (int i = 0; i < V; ++i) if (i < rv[i]) swap(f[i], f[rv[i]]);
for (int k = 2; k <= V; k <<= 1) {
int rk = k >> 1, w = pw(G, (mod - 1) / k);
for (int i = 0; i < V; i += k) {
int r = 1;
for (int j = i; j < i + rk; ++j) {
int g = mul(f[j + rk], r);
f[j + rk] = sub(f[j], g);
Add(f[j], g);
Mul(r, w);
}
}
}
if (!ag) {
int iV = pw(V, mod - 2);
reverse(f + 1, f + V);
for (int i = 0; i < V; ++i) Mul(f[i], iV);
}
}
void mulp(int f[], int g[]) {
static int h[V];
memset(h, 0, sizeof h);
for (int v1 = 0; v1 < V; ++v1) {
for (int v2 = 0; v1 + v2 < V; ++v2) {
Fav(h[v1 + v2], f[v1], g[v2]);
}
}
for (int i = 0; i < V; ++i) cout << g[i] << ' '; cout << '\n';
for (int i = 0; i < V; ++i) cout << f[i] << ' '; cout << '\n';
for (int i = 0; i < V; ++i) cout << h[i] << ' '; cout << '\n';
NTT(g);
NTT(f);
for (int i = 0; i < V; ++i) Mul(g[i], f[i]);
NTT(g, 0);
NTT(f, 0);
for (int i = 0; i < V; ++i) cout << g[i] << ' '; cout << '\n';
cout << '\n';
}
int main() {
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
init();
n = read(), q = read();
read();
// mod = read();
for (int i = 0; i < n; ++i) {
int a = read();
f[i][0] = 1;
for (int r = 0; r < a; ++r) {
int b = read(), c = read();
static int g[V];
for (int k = 0; k < Vp; ++k) g[k] = add(f[i][k], (k >= b ? g[k - b] : 0));
for (int k = 0; k < Vp; ++k) f[i][k] = sub(g[k], (k >= b * (c + 1) ? g[k - b * (c + 1)] : 0));
}
memcpy(vf[i][0], f[i], V << 2);
for (int k = 0; k < Vp - 1; ++k) {
memcpy(vf[i][k + 1] + k + 1, vf[i][k] + k + 1, (V - k - 1) << 2);
NTT(vf[i][k]);
}
NTT(vf[i][520]);
}
for (int i = 0; i < q; ++i) {
char s[20];
int m, k, v = 0;
scanf("%s%d%d", s, &m, &k);
for (int j = 0; j < n; ++j) if (s[j] == '1') v |= 1 << j;
int lw = k * __builtin_popcount(v);
if (lw > m) {
cout << 0 << '\n';
continue;
}
static int g[V];
/*
memset(g, 0, V << 2);
g[0] = 1;
for (int j = 0; j < n; ++j) {
if ((v >> j) & 1) {
mulp(vf[j][k], g);
} else {
mulp(vf[j][0], g);
}
}
*/
for (int i = 0; i < V; ++i) g[i] = 1;
for (int j = 0; j < n; ++j) {
if ((v >> j) & 1) {
for (int i = 0; i < V; ++i) Mul(g[i], vf[j][k][i]);
} else {
for (int i = 0; i < V; ++i) Mul(g[i], vf[j][0][i]);
}
}
NTT(g, 0);
int ans = 0;
for (int j = 0; j <= m; ++j) Add(ans, g[j]);
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 31ms
memory: 6940kb
input:
1 521 998244353 39 520 520 11 22 414 8 95 18 229 356 26 407 316 10 24 26 19 61 11 130 482 476 420 15 192 193 208 24 19 233 494 217 275 294 26 28 439 20 272 277 28 198 5 335 22 8 28 17 154 78 6 13 175 17 2 5 477 256 200 4 1 36 427 371 439 23 10 65 426 25 24 27 121 29 28 13 12 453 0 520 1 1 519 1 1 51...
output:
38813347 922143638 98254957 38813343 922143633 38813338 98254946 922143620 98254933 922143604 38813302 38813288 922143562 38813247 38813220 38813188 38813150 98254715 38813047 922143273 98254516 38812814 922142999 98254191 922142723 38812257 38812058 98253436 922141847 38811240 922141173 38810463 38...
result:
ok 521 lines
Test #2:
score: -3
Wrong Answer
time: 65ms
memory: 8488kb
input:
2 1561 998244353 151 520 520 511 30 121 396 25 16 113 11 6 175 242 20 8 5 61 13 518 447 404 8 220 177 4 19 18 15 70 233 9 14 26 512 17 9 9 19 30 8 495 20 13 27 277 22 396 14 4 29 345 442 19 25 14 5 16 295 19 65 134 10 10 296 245 6 7 30 253 15 187 26 482 454 28 414 170 404 11 27 27 25 13 509 1 5 291 ...
output:
823177542 83560359 701286559 51508703 324975575 760930535 613186890 818961990 867154893 75662431 375796551 552157894 707474141 553097267 976760409 791436664 154808185 90958034 905165482 909045860 603264944 397459289 820272179 817696423 720784943 556155983 789537373 235325041 614041101 826604547 6165...
result:
wrong answer 1st lines differ - expected: '883965618', found: '823177542'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #9:
score: 10
Accepted
time: 2497ms
memory: 34852kb
input:
15 52099 998244353 1 9 3 1 9 4 1 9 2 1 8 10 1 4 4 1 3 1 1 2 5 1 4 9 1 1 4 1 9 4 1 7 6 1 1 6 1 2 5 1 5 2 1 3 5 101000000001010 516 1 010001001010101 520 2 000000101000001 519 2 101011111100011 518 1 010110001000111 520 2 000110111100111 516 1 000100101001011 519 3 000111001010011 518 1 00001110010111...
output:
993379058 496689529 866368587 797687294 481245176 481245176 39022588 269889529 552778235 769822588 331666941 99789529 903956470 112750588 756797435 519045176 870912000 361582588 594280447 494747647 597778941 178845176 435456000 493445999 461733882 308912117 271186941 496689529 919511294 85533882 894...
result:
ok 52099 lines
Test #10:
score: -10
Wrong Answer
time: 2529ms
memory: 34772kb
input:
15 52099 998244353 1 444 1 1 184 2 1 427 1 1 23 1 1 513 2 1 413 4 1 304 2 1 214 5 1 108 2 1 304 1 1 283 5 1 465 1 1 277 1 1 57 2 1 160 4 111010111100101 520 25 010010011100110 520 3 010000011011000 519 36 110011011100110 516 21 010110001101101 516 42 100001101000111 520 31 110001100010001 519 10 110...
output:
581 4168 12478 1024 0 3514 5245 4677 1165 6986 576 1166 1730 0 0 0 0 4673 438 2530 0 1725 14082 0 1759 2341 0 0 2631 3506 638 0 9382 133 0 0 1756 14033 0 776 0 5260 0 290 1742 760 3500 2323 0 0 0 1173 3935 423 872 7024 21103 2283 1549 1262 0 0 423 0 0 0 0 1758 0 1168 875 9308 1549 6981 1752 3497 290...
result:
wrong answer 1st lines differ - expected: '0', found: '581'
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%