# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
385901 | 2021-04-05T07:58:38 Z | ntabc05101 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1138 ms | 47632 KB |
#include<bits/stdc++.h> using namespace std; #define LL long long int main() { ios_base::sync_with_stdio(0); cin.tie(0); int L, Q; string S; cin >> L >> Q >> S; int M = 1 << L; int sup[M], sub[M], c[M]; for (int i = 0; i < M; i++) { sup[i] = sub[i] = c[i] = S[i] - '0'; } int n_bit[M]; for (int i = 0; i < M; i++) { n_bit[i] = __builtin_popcount(i); } for (int i = 0; i < L; i++) { for (int j = 0; j < M; j++) { if (j >> i & 1) { sub[j] += sub[j ^ (1 << i)]; } else { sup[j] += sup[j ^ (1 << i)]; } } } while (Q--) { cin >> S; reverse(begin(S), end(S)); int A = 0, B = 0, C = 0; for (int i = 0; i < L; i++) { if (S[i] == '0') { A |= 1 << i; } else if (S[i] == '1') { B |= 1 << i; } else { C |= 1 << i; } } int result = 0; if (n_bit[A] <= L / 3) { result = sup[B]; for (int i = A; i > 0; i = (i - 1) & A) { result += (1 - ((n_bit[i] & 1) << 1)) * sup[B | i]; } } else if (n_bit[B] <= L / 3) { result = sub[M - 1 ^ A]; for (int i = B; i > 0; i = (i - 1) & B) { result += (1 - ((n_bit[i] & 1) << 1)) * sub[M - 1 ^ (A | i)]; } } else if (n_bit[C] <= L / 3) { result = c[B]; for (int i = C; i > 0; i = (i - 1) & C) { result += c[B | i]; } } cout << result << "\n"; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 239 ms | 15340 KB | Output is correct |
12 | Correct | 248 ms | 14792 KB | Output is correct |
13 | Correct | 282 ms | 14060 KB | Output is correct |
14 | Correct | 277 ms | 14188 KB | Output is correct |
15 | Correct | 258 ms | 15084 KB | Output is correct |
16 | Correct | 338 ms | 14444 KB | Output is correct |
17 | Correct | 297 ms | 14316 KB | Output is correct |
18 | Correct | 193 ms | 16108 KB | Output is correct |
19 | Correct | 250 ms | 13164 KB | Output is correct |
20 | Correct | 255 ms | 14956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 239 ms | 15340 KB | Output is correct |
12 | Correct | 248 ms | 14792 KB | Output is correct |
13 | Correct | 282 ms | 14060 KB | Output is correct |
14 | Correct | 277 ms | 14188 KB | Output is correct |
15 | Correct | 258 ms | 15084 KB | Output is correct |
16 | Correct | 338 ms | 14444 KB | Output is correct |
17 | Correct | 297 ms | 14316 KB | Output is correct |
18 | Correct | 193 ms | 16108 KB | Output is correct |
19 | Correct | 250 ms | 13164 KB | Output is correct |
20 | Correct | 255 ms | 14956 KB | Output is correct |
21 | Correct | 265 ms | 18156 KB | Output is correct |
22 | Correct | 285 ms | 18540 KB | Output is correct |
23 | Correct | 344 ms | 17468 KB | Output is correct |
24 | Correct | 330 ms | 17260 KB | Output is correct |
25 | Correct | 290 ms | 19332 KB | Output is correct |
26 | Correct | 349 ms | 17900 KB | Output is correct |
27 | Correct | 341 ms | 17644 KB | Output is correct |
28 | Correct | 215 ms | 20332 KB | Output is correct |
29 | Correct | 257 ms | 16236 KB | Output is correct |
30 | Correct | 282 ms | 18412 KB | Output is correct |
31 | Correct | 319 ms | 18308 KB | Output is correct |
32 | Correct | 340 ms | 18412 KB | Output is correct |
33 | Correct | 290 ms | 17260 KB | Output is correct |
34 | Correct | 337 ms | 17244 KB | Output is correct |
35 | Correct | 345 ms | 17772 KB | Output is correct |
36 | Correct | 232 ms | 16204 KB | Output is correct |
37 | Correct | 264 ms | 18284 KB | Output is correct |
38 | Correct | 282 ms | 16236 KB | Output is correct |
39 | Correct | 314 ms | 17388 KB | Output is correct |
40 | Correct | 334 ms | 17260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 60 ms | 20240 KB | Output is correct |
12 | Correct | 65 ms | 20240 KB | Output is correct |
13 | Correct | 75 ms | 20240 KB | Output is correct |
14 | Correct | 88 ms | 20112 KB | Output is correct |
15 | Correct | 62 ms | 20240 KB | Output is correct |
16 | Correct | 89 ms | 20240 KB | Output is correct |
17 | Correct | 89 ms | 20240 KB | Output is correct |
18 | Correct | 51 ms | 20368 KB | Output is correct |
19 | Correct | 61 ms | 20240 KB | Output is correct |
20 | Correct | 59 ms | 20240 KB | Output is correct |
21 | Correct | 70 ms | 20240 KB | Output is correct |
22 | Correct | 91 ms | 20240 KB | Output is correct |
23 | Correct | 60 ms | 20112 KB | Output is correct |
24 | Correct | 92 ms | 20112 KB | Output is correct |
25 | Correct | 88 ms | 20240 KB | Output is correct |
26 | Correct | 54 ms | 20132 KB | Output is correct |
27 | Correct | 58 ms | 20240 KB | Output is correct |
28 | Correct | 63 ms | 20112 KB | Output is correct |
29 | Correct | 72 ms | 20112 KB | Output is correct |
30 | Correct | 76 ms | 20112 KB | Output is correct |
31 | Correct | 63 ms | 20112 KB | Output is correct |
32 | Correct | 92 ms | 20240 KB | Output is correct |
33 | Correct | 86 ms | 20240 KB | Output is correct |
34 | Correct | 53 ms | 20112 KB | Output is correct |
35 | Correct | 80 ms | 20344 KB | Output is correct |
36 | Correct | 94 ms | 20240 KB | Output is correct |
37 | Correct | 80 ms | 20240 KB | Output is correct |
38 | Correct | 77 ms | 20184 KB | Output is correct |
39 | Correct | 77 ms | 20240 KB | Output is correct |
40 | Correct | 79 ms | 20112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 239 ms | 15340 KB | Output is correct |
12 | Correct | 248 ms | 14792 KB | Output is correct |
13 | Correct | 282 ms | 14060 KB | Output is correct |
14 | Correct | 277 ms | 14188 KB | Output is correct |
15 | Correct | 258 ms | 15084 KB | Output is correct |
16 | Correct | 338 ms | 14444 KB | Output is correct |
17 | Correct | 297 ms | 14316 KB | Output is correct |
18 | Correct | 193 ms | 16108 KB | Output is correct |
19 | Correct | 250 ms | 13164 KB | Output is correct |
20 | Correct | 255 ms | 14956 KB | Output is correct |
21 | Correct | 265 ms | 18156 KB | Output is correct |
22 | Correct | 285 ms | 18540 KB | Output is correct |
23 | Correct | 344 ms | 17468 KB | Output is correct |
24 | Correct | 330 ms | 17260 KB | Output is correct |
25 | Correct | 290 ms | 19332 KB | Output is correct |
26 | Correct | 349 ms | 17900 KB | Output is correct |
27 | Correct | 341 ms | 17644 KB | Output is correct |
28 | Correct | 215 ms | 20332 KB | Output is correct |
29 | Correct | 257 ms | 16236 KB | Output is correct |
30 | Correct | 282 ms | 18412 KB | Output is correct |
31 | Correct | 319 ms | 18308 KB | Output is correct |
32 | Correct | 340 ms | 18412 KB | Output is correct |
33 | Correct | 290 ms | 17260 KB | Output is correct |
34 | Correct | 337 ms | 17244 KB | Output is correct |
35 | Correct | 345 ms | 17772 KB | Output is correct |
36 | Correct | 232 ms | 16204 KB | Output is correct |
37 | Correct | 264 ms | 18284 KB | Output is correct |
38 | Correct | 282 ms | 16236 KB | Output is correct |
39 | Correct | 314 ms | 17388 KB | Output is correct |
40 | Correct | 334 ms | 17260 KB | Output is correct |
41 | Correct | 60 ms | 20240 KB | Output is correct |
42 | Correct | 65 ms | 20240 KB | Output is correct |
43 | Correct | 75 ms | 20240 KB | Output is correct |
44 | Correct | 88 ms | 20112 KB | Output is correct |
45 | Correct | 62 ms | 20240 KB | Output is correct |
46 | Correct | 89 ms | 20240 KB | Output is correct |
47 | Correct | 89 ms | 20240 KB | Output is correct |
48 | Correct | 51 ms | 20368 KB | Output is correct |
49 | Correct | 61 ms | 20240 KB | Output is correct |
50 | Correct | 59 ms | 20240 KB | Output is correct |
51 | Correct | 70 ms | 20240 KB | Output is correct |
52 | Correct | 91 ms | 20240 KB | Output is correct |
53 | Correct | 60 ms | 20112 KB | Output is correct |
54 | Correct | 92 ms | 20112 KB | Output is correct |
55 | Correct | 88 ms | 20240 KB | Output is correct |
56 | Correct | 54 ms | 20132 KB | Output is correct |
57 | Correct | 58 ms | 20240 KB | Output is correct |
58 | Correct | 63 ms | 20112 KB | Output is correct |
59 | Correct | 72 ms | 20112 KB | Output is correct |
60 | Correct | 76 ms | 20112 KB | Output is correct |
61 | Correct | 63 ms | 20112 KB | Output is correct |
62 | Correct | 92 ms | 20240 KB | Output is correct |
63 | Correct | 86 ms | 20240 KB | Output is correct |
64 | Correct | 53 ms | 20112 KB | Output is correct |
65 | Correct | 80 ms | 20344 KB | Output is correct |
66 | Correct | 94 ms | 20240 KB | Output is correct |
67 | Correct | 80 ms | 20240 KB | Output is correct |
68 | Correct | 77 ms | 20184 KB | Output is correct |
69 | Correct | 77 ms | 20240 KB | Output is correct |
70 | Correct | 79 ms | 20112 KB | Output is correct |
71 | Correct | 411 ms | 44560 KB | Output is correct |
72 | Correct | 514 ms | 44888 KB | Output is correct |
73 | Correct | 741 ms | 43280 KB | Output is correct |
74 | Correct | 898 ms | 43536 KB | Output is correct |
75 | Correct | 508 ms | 45620 KB | Output is correct |
76 | Correct | 916 ms | 43908 KB | Output is correct |
77 | Correct | 1033 ms | 43884 KB | Output is correct |
78 | Correct | 273 ms | 47632 KB | Output is correct |
79 | Correct | 467 ms | 41488 KB | Output is correct |
80 | Correct | 451 ms | 44644 KB | Output is correct |
81 | Correct | 659 ms | 44688 KB | Output is correct |
82 | Correct | 940 ms | 43536 KB | Output is correct |
83 | Correct | 462 ms | 42636 KB | Output is correct |
84 | Correct | 1098 ms | 43552 KB | Output is correct |
85 | Correct | 983 ms | 43912 KB | Output is correct |
86 | Correct | 275 ms | 41616 KB | Output is correct |
87 | Correct | 450 ms | 44560 KB | Output is correct |
88 | Correct | 542 ms | 41488 KB | Output is correct |
89 | Correct | 647 ms | 43152 KB | Output is correct |
90 | Correct | 774 ms | 43536 KB | Output is correct |
91 | Correct | 547 ms | 42892 KB | Output is correct |
92 | Correct | 1138 ms | 44048 KB | Output is correct |
93 | Correct | 984 ms | 43852 KB | Output is correct |
94 | Correct | 268 ms | 41628 KB | Output is correct |
95 | Correct | 901 ms | 43712 KB | Output is correct |
96 | Correct | 870 ms | 43792 KB | Output is correct |
97 | Correct | 876 ms | 43664 KB | Output is correct |
98 | Correct | 836 ms | 43788 KB | Output is correct |
99 | Correct | 825 ms | 43760 KB | Output is correct |
100 | Correct | 850 ms | 43720 KB | Output is correct |