# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
204076 | 2020-02-24T08:39:59 Z | Kastanda | Snake Escaping (JOI18_snake_escaping) | C++11 | 1435 ms | 40596 KB |
// In The Name Of The Queen #include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; const int N = 20, K = 12, M = 8, MXK = 531441, MXM = 6561, MAXQ = 1e6 + 9; // MXK = 3 ^ K, MXM = 3 ^ M int n, q, k, m, RS[MAXQ], Val[MAXQ]; int L[MXK], R[MXK], B[MXK], dp[MXK]; char A[1 << N], Tmp[N]; vector < int > Q[MXM]; int main() { scanf("%d%d%s", &n, &q, A); for (int i = 0; i < (1 << n); i ++) A[i] -= '0'; k = min(K, n); m = n - k; for (int i = 0; i < q; i ++) { scanf("%s", Tmp); for (int j = 0; j < n; j ++) { if (Tmp[j] == '?') Tmp[j] = '2'; Tmp[j] -= '0'; } int pref = 0; for (int j = 0; j < m; j ++) pref = (pref << 1) + pref + Tmp[j]; int suff = 0; for (int j = m; j < n; j ++) suff = (suff << 1) + suff + Tmp[j]; Val[i] = suff; Q[pref].push_back(i); } int k3 = 1; for (int i = 0; i < k; i ++) k3 *= 3; for (int state = 0; state < k3; state ++) { int tmp = state; for (int j = 0; j < k; j ++) Tmp[j] = tmp % 3, tmp /= 3; int h = -1; for (int j = 0; j < k; j ++) if (Tmp[j] == 2) h = j; if (h == -1) { for (int j = 0; j < k; j ++) B[state] |= Tmp[j] << j; continue; } B[state] = -1; Tmp[h] = 0; for (int j = k - 1; ~ j; j --) L[state] = L[state] * 3 + Tmp[j]; Tmp[h] = 1; for (int j = k - 1; ~ j; j --) R[state] = R[state] * 3 + Tmp[j]; } for (int mask = 0; mask < (1 << m); mask ++) { for (int state = 0; state < k3; state ++) { if (B[state] != -1) dp[state] = A[(mask << k) | B[state]]; else dp[state] = dp[L[state]] + dp[R[state]]; } for (int sk = 0; sk < (1 << m); sk ++) { for (int j = 0; j < m; j ++) { if (sk >> j & 1) Tmp[j] = 2; else Tmp[j] = mask >> j & 1; } int pref = 0; for (int j = m - 1; ~ j; j --) pref = pref * 3 + Tmp[j]; for (int i : Q[pref]) RS[i] += dp[Val[i]]; } } for (int i = 0; i < q; i ++) printf("%d\n", RS[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1400 KB | Output is correct |
6 | Correct | 8 ms | 1404 KB | Output is correct |
7 | Correct | 9 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1400 KB | Output is correct |
9 | Correct | 8 ms | 1404 KB | Output is correct |
10 | Correct | 8 ms | 1400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1400 KB | Output is correct |
6 | Correct | 8 ms | 1404 KB | Output is correct |
7 | Correct | 9 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1400 KB | Output is correct |
9 | Correct | 8 ms | 1404 KB | Output is correct |
10 | Correct | 8 ms | 1400 KB | Output is correct |
11 | Correct | 272 ms | 28124 KB | Output is correct |
12 | Correct | 276 ms | 27740 KB | Output is correct |
13 | Correct | 274 ms | 27100 KB | Output is correct |
14 | Correct | 273 ms | 27100 KB | Output is correct |
15 | Correct | 273 ms | 28160 KB | Output is correct |
16 | Correct | 269 ms | 27228 KB | Output is correct |
17 | Correct | 286 ms | 27228 KB | Output is correct |
18 | Correct | 273 ms | 29148 KB | Output is correct |
19 | Correct | 273 ms | 26204 KB | Output is correct |
20 | Correct | 280 ms | 27868 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1400 KB | Output is correct |
6 | Correct | 8 ms | 1404 KB | Output is correct |
7 | Correct | 9 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1400 KB | Output is correct |
9 | Correct | 8 ms | 1404 KB | Output is correct |
10 | Correct | 8 ms | 1400 KB | Output is correct |
11 | Correct | 272 ms | 28124 KB | Output is correct |
12 | Correct | 276 ms | 27740 KB | Output is correct |
13 | Correct | 274 ms | 27100 KB | Output is correct |
14 | Correct | 273 ms | 27100 KB | Output is correct |
15 | Correct | 273 ms | 28160 KB | Output is correct |
16 | Correct | 269 ms | 27228 KB | Output is correct |
17 | Correct | 286 ms | 27228 KB | Output is correct |
18 | Correct | 273 ms | 29148 KB | Output is correct |
19 | Correct | 273 ms | 26204 KB | Output is correct |
20 | Correct | 280 ms | 27868 KB | Output is correct |
21 | Correct | 318 ms | 38736 KB | Output is correct |
22 | Correct | 322 ms | 38552 KB | Output is correct |
23 | Correct | 320 ms | 37664 KB | Output is correct |
24 | Correct | 331 ms | 37452 KB | Output is correct |
25 | Correct | 314 ms | 40596 KB | Output is correct |
26 | Correct | 327 ms | 37832 KB | Output is correct |
27 | Correct | 338 ms | 38244 KB | Output is correct |
28 | Correct | 322 ms | 40552 KB | Output is correct |
29 | Correct | 317 ms | 36520 KB | Output is correct |
30 | Correct | 339 ms | 38780 KB | Output is correct |
31 | Correct | 329 ms | 38304 KB | Output is correct |
32 | Correct | 338 ms | 38344 KB | Output is correct |
33 | Correct | 325 ms | 38240 KB | Output is correct |
34 | Correct | 315 ms | 37448 KB | Output is correct |
35 | Correct | 333 ms | 38052 KB | Output is correct |
36 | Correct | 312 ms | 36460 KB | Output is correct |
37 | Correct | 317 ms | 38476 KB | Output is correct |
38 | Correct | 311 ms | 36564 KB | Output is correct |
39 | Correct | 326 ms | 37704 KB | Output is correct |
40 | Correct | 313 ms | 37452 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1400 KB | Output is correct |
6 | Correct | 8 ms | 1404 KB | Output is correct |
7 | Correct | 9 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1400 KB | Output is correct |
9 | Correct | 8 ms | 1404 KB | Output is correct |
10 | Correct | 8 ms | 1400 KB | Output is correct |
11 | Correct | 265 ms | 12980 KB | Output is correct |
12 | Correct | 265 ms | 12792 KB | Output is correct |
13 | Correct | 257 ms | 12920 KB | Output is correct |
14 | Correct | 264 ms | 12920 KB | Output is correct |
15 | Correct | 270 ms | 12920 KB | Output is correct |
16 | Correct | 279 ms | 12920 KB | Output is correct |
17 | Correct | 260 ms | 12924 KB | Output is correct |
18 | Correct | 286 ms | 13044 KB | Output is correct |
19 | Correct | 243 ms | 12664 KB | Output is correct |
20 | Correct | 254 ms | 12924 KB | Output is correct |
21 | Correct | 268 ms | 13048 KB | Output is correct |
22 | Correct | 253 ms | 12920 KB | Output is correct |
23 | Correct | 250 ms | 12792 KB | Output is correct |
24 | Correct | 258 ms | 12920 KB | Output is correct |
25 | Correct | 264 ms | 12920 KB | Output is correct |
26 | Correct | 242 ms | 12660 KB | Output is correct |
27 | Correct | 252 ms | 12792 KB | Output is correct |
28 | Correct | 245 ms | 12792 KB | Output is correct |
29 | Correct | 265 ms | 12920 KB | Output is correct |
30 | Correct | 262 ms | 12920 KB | Output is correct |
31 | Correct | 251 ms | 12792 KB | Output is correct |
32 | Correct | 272 ms | 12924 KB | Output is correct |
33 | Correct | 258 ms | 12920 KB | Output is correct |
34 | Correct | 250 ms | 12660 KB | Output is correct |
35 | Correct | 270 ms | 12920 KB | Output is correct |
36 | Correct | 264 ms | 12920 KB | Output is correct |
37 | Correct | 287 ms | 12920 KB | Output is correct |
38 | Correct | 270 ms | 12920 KB | Output is correct |
39 | Correct | 278 ms | 12920 KB | Output is correct |
40 | Correct | 268 ms | 12792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1400 KB | Output is correct |
6 | Correct | 8 ms | 1404 KB | Output is correct |
7 | Correct | 9 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1400 KB | Output is correct |
9 | Correct | 8 ms | 1404 KB | Output is correct |
10 | Correct | 8 ms | 1400 KB | Output is correct |
11 | Correct | 272 ms | 28124 KB | Output is correct |
12 | Correct | 276 ms | 27740 KB | Output is correct |
13 | Correct | 274 ms | 27100 KB | Output is correct |
14 | Correct | 273 ms | 27100 KB | Output is correct |
15 | Correct | 273 ms | 28160 KB | Output is correct |
16 | Correct | 269 ms | 27228 KB | Output is correct |
17 | Correct | 286 ms | 27228 KB | Output is correct |
18 | Correct | 273 ms | 29148 KB | Output is correct |
19 | Correct | 273 ms | 26204 KB | Output is correct |
20 | Correct | 280 ms | 27868 KB | Output is correct |
21 | Correct | 318 ms | 38736 KB | Output is correct |
22 | Correct | 322 ms | 38552 KB | Output is correct |
23 | Correct | 320 ms | 37664 KB | Output is correct |
24 | Correct | 331 ms | 37452 KB | Output is correct |
25 | Correct | 314 ms | 40596 KB | Output is correct |
26 | Correct | 327 ms | 37832 KB | Output is correct |
27 | Correct | 338 ms | 38244 KB | Output is correct |
28 | Correct | 322 ms | 40552 KB | Output is correct |
29 | Correct | 317 ms | 36520 KB | Output is correct |
30 | Correct | 339 ms | 38780 KB | Output is correct |
31 | Correct | 329 ms | 38304 KB | Output is correct |
32 | Correct | 338 ms | 38344 KB | Output is correct |
33 | Correct | 325 ms | 38240 KB | Output is correct |
34 | Correct | 315 ms | 37448 KB | Output is correct |
35 | Correct | 333 ms | 38052 KB | Output is correct |
36 | Correct | 312 ms | 36460 KB | Output is correct |
37 | Correct | 317 ms | 38476 KB | Output is correct |
38 | Correct | 311 ms | 36564 KB | Output is correct |
39 | Correct | 326 ms | 37704 KB | Output is correct |
40 | Correct | 313 ms | 37452 KB | Output is correct |
41 | Correct | 265 ms | 12980 KB | Output is correct |
42 | Correct | 265 ms | 12792 KB | Output is correct |
43 | Correct | 257 ms | 12920 KB | Output is correct |
44 | Correct | 264 ms | 12920 KB | Output is correct |
45 | Correct | 270 ms | 12920 KB | Output is correct |
46 | Correct | 279 ms | 12920 KB | Output is correct |
47 | Correct | 260 ms | 12924 KB | Output is correct |
48 | Correct | 286 ms | 13044 KB | Output is correct |
49 | Correct | 243 ms | 12664 KB | Output is correct |
50 | Correct | 254 ms | 12924 KB | Output is correct |
51 | Correct | 268 ms | 13048 KB | Output is correct |
52 | Correct | 253 ms | 12920 KB | Output is correct |
53 | Correct | 250 ms | 12792 KB | Output is correct |
54 | Correct | 258 ms | 12920 KB | Output is correct |
55 | Correct | 264 ms | 12920 KB | Output is correct |
56 | Correct | 242 ms | 12660 KB | Output is correct |
57 | Correct | 252 ms | 12792 KB | Output is correct |
58 | Correct | 245 ms | 12792 KB | Output is correct |
59 | Correct | 265 ms | 12920 KB | Output is correct |
60 | Correct | 262 ms | 12920 KB | Output is correct |
61 | Correct | 251 ms | 12792 KB | Output is correct |
62 | Correct | 272 ms | 12924 KB | Output is correct |
63 | Correct | 258 ms | 12920 KB | Output is correct |
64 | Correct | 250 ms | 12660 KB | Output is correct |
65 | Correct | 270 ms | 12920 KB | Output is correct |
66 | Correct | 264 ms | 12920 KB | Output is correct |
67 | Correct | 287 ms | 12920 KB | Output is correct |
68 | Correct | 270 ms | 12920 KB | Output is correct |
69 | Correct | 278 ms | 12920 KB | Output is correct |
70 | Correct | 268 ms | 12792 KB | Output is correct |
71 | Correct | 783 ms | 30456 KB | Output is correct |
72 | Correct | 821 ms | 28280 KB | Output is correct |
73 | Correct | 688 ms | 29560 KB | Output is correct |
74 | Correct | 777 ms | 28512 KB | Output is correct |
75 | Correct | 1309 ms | 30584 KB | Output is correct |
76 | Correct | 825 ms | 28976 KB | Output is correct |
77 | Correct | 808 ms | 30200 KB | Output is correct |
78 | Correct | 1435 ms | 30684 KB | Output is correct |
79 | Correct | 534 ms | 27000 KB | Output is correct |
80 | Correct | 827 ms | 28152 KB | Output is correct |
81 | Correct | 1080 ms | 30840 KB | Output is correct |
82 | Correct | 813 ms | 28408 KB | Output is correct |
83 | Correct | 619 ms | 27896 KB | Output is correct |
84 | Correct | 743 ms | 28640 KB | Output is correct |
85 | Correct | 856 ms | 30072 KB | Output is correct |
86 | Correct | 509 ms | 24560 KB | Output is correct |
87 | Correct | 786 ms | 30072 KB | Output is correct |
88 | Correct | 536 ms | 25224 KB | Output is correct |
89 | Correct | 701 ms | 29432 KB | Output is correct |
90 | Correct | 736 ms | 28408 KB | Output is correct |
91 | Correct | 625 ms | 27640 KB | Output is correct |
92 | Correct | 858 ms | 28924 KB | Output is correct |
93 | Correct | 841 ms | 30072 KB | Output is correct |
94 | Correct | 505 ms | 24516 KB | Output is correct |
95 | Correct | 940 ms | 28288 KB | Output is correct |
96 | Correct | 962 ms | 28268 KB | Output is correct |
97 | Correct | 972 ms | 28140 KB | Output is correct |
98 | Correct | 957 ms | 28268 KB | Output is correct |
99 | Correct | 966 ms | 28140 KB | Output is correct |
100 | Correct | 956 ms | 28012 KB | Output is correct |