# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735817 | 2023-05-04T17:48:27 Z | lovrot | Snake Escaping (JOI18_snake_escaping) | C++17 | 1910 ms | 46300 KB |
#include <cstdio> #include <vector> #include <cstring> #include <string> #include <algorithm> #define X first #define Y second #define pb push_back using namespace std; typedef pair<int, int> pii; const int LOG = 20; const int OFF = 1 << LOG; int n, m, P[OFF], sum; int POP[OFF], SUB[OFF], HIP[OFF]; int count(int mask) { return __builtin_popcount(mask); } int main() { scanf("%d%d", &n, &m); int off = 1 << n; for(int i = 0; i < off; i++) { char c; scanf(" %c", &c); P[i] = c - '0'; SUB[i] = HIP[i] = P[i]; sum += P[i]; POP[i] = count(i); } for(int i = 0; i < n; i++) for(int mask = 0; mask < off; mask++) { if(mask & 1 << i) SUB[mask] += SUB[mask ^ 1 << i]; else HIP[mask] += HIP[mask ^ 1 << i]; } for(int t = 0; t < m; t++) { int zer = 0; int one = 0; int que = 0; for(int i = 0, j = n - 1; i < n; i++, j--) { char c; scanf(" %c", &c); if(c == '?') que |= 1 << j; else if (c == '1') one |= 1 << j; else zer |= 1 << j; } int nim = min({POP[zer], POP[que], POP[one]}); int sol = 0; if(POP[zer] == nim) { //0 for(int mask = zer; ; mask = (mask - 1) & zer) { sol += (POP[mask] & 1 ? -1 : 1) * HIP[mask | one]; if(mask == 0) break; } } else if(POP[one] == nim) { //1 for(int mask = one; ; mask = (mask - 1) & one) { sol += (POP[mask] & 1 ? -1 : 1) * SUB[que | (one ^ mask)]; if(mask == 0) break; } } else { //? for(int mask = que; ; mask = (mask - 1) & que) { sol += P[mask | one]; if(mask == 0) break; } } printf("%d\n", sol); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 656 ms | 15120 KB | Output is correct |
12 | Correct | 641 ms | 14876 KB | Output is correct |
13 | Correct | 633 ms | 13992 KB | Output is correct |
14 | Correct | 656 ms | 13980 KB | Output is correct |
15 | Correct | 628 ms | 15136 KB | Output is correct |
16 | Correct | 660 ms | 14276 KB | Output is correct |
17 | Correct | 675 ms | 14240 KB | Output is correct |
18 | Correct | 527 ms | 16104 KB | Output is correct |
19 | Correct | 608 ms | 13008 KB | Output is correct |
20 | Correct | 618 ms | 14704 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 656 ms | 15120 KB | Output is correct |
12 | Correct | 641 ms | 14876 KB | Output is correct |
13 | Correct | 633 ms | 13992 KB | Output is correct |
14 | Correct | 656 ms | 13980 KB | Output is correct |
15 | Correct | 628 ms | 15136 KB | Output is correct |
16 | Correct | 660 ms | 14276 KB | Output is correct |
17 | Correct | 675 ms | 14240 KB | Output is correct |
18 | Correct | 527 ms | 16104 KB | Output is correct |
19 | Correct | 608 ms | 13008 KB | Output is correct |
20 | Correct | 618 ms | 14704 KB | Output is correct |
21 | Correct | 740 ms | 18096 KB | Output is correct |
22 | Correct | 775 ms | 18320 KB | Output is correct |
23 | Correct | 822 ms | 17376 KB | Output is correct |
24 | Correct | 889 ms | 17188 KB | Output is correct |
25 | Correct | 768 ms | 19064 KB | Output is correct |
26 | Correct | 855 ms | 17648 KB | Output is correct |
27 | Correct | 849 ms | 17564 KB | Output is correct |
28 | Correct | 667 ms | 20052 KB | Output is correct |
29 | Correct | 797 ms | 16288 KB | Output is correct |
30 | Correct | 802 ms | 18392 KB | Output is correct |
31 | Correct | 854 ms | 18088 KB | Output is correct |
32 | Correct | 877 ms | 18176 KB | Output is correct |
33 | Correct | 756 ms | 17004 KB | Output is correct |
34 | Correct | 840 ms | 17136 KB | Output is correct |
35 | Correct | 860 ms | 17724 KB | Output is correct |
36 | Correct | 679 ms | 16276 KB | Output is correct |
37 | Correct | 815 ms | 18060 KB | Output is correct |
38 | Correct | 738 ms | 16216 KB | Output is correct |
39 | Correct | 872 ms | 17252 KB | Output is correct |
40 | Correct | 798 ms | 17160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 138 ms | 19092 KB | Output is correct |
12 | Correct | 143 ms | 18864 KB | Output is correct |
13 | Correct | 137 ms | 18796 KB | Output is correct |
14 | Correct | 144 ms | 18836 KB | Output is correct |
15 | Correct | 163 ms | 19196 KB | Output is correct |
16 | Correct | 152 ms | 18904 KB | Output is correct |
17 | Correct | 162 ms | 18884 KB | Output is correct |
18 | Correct | 164 ms | 19092 KB | Output is correct |
19 | Correct | 136 ms | 18840 KB | Output is correct |
20 | Correct | 135 ms | 18928 KB | Output is correct |
21 | Correct | 172 ms | 18872 KB | Output is correct |
22 | Correct | 161 ms | 19116 KB | Output is correct |
23 | Correct | 126 ms | 18844 KB | Output is correct |
24 | Correct | 156 ms | 18968 KB | Output is correct |
25 | Correct | 166 ms | 18912 KB | Output is correct |
26 | Correct | 125 ms | 18760 KB | Output is correct |
27 | Correct | 138 ms | 18892 KB | Output is correct |
28 | Correct | 140 ms | 18752 KB | Output is correct |
29 | Correct | 145 ms | 18816 KB | Output is correct |
30 | Correct | 152 ms | 18892 KB | Output is correct |
31 | Correct | 153 ms | 18828 KB | Output is correct |
32 | Correct | 167 ms | 18880 KB | Output is correct |
33 | Correct | 179 ms | 18848 KB | Output is correct |
34 | Correct | 143 ms | 18724 KB | Output is correct |
35 | Correct | 162 ms | 18984 KB | Output is correct |
36 | Correct | 159 ms | 18892 KB | Output is correct |
37 | Correct | 168 ms | 18888 KB | Output is correct |
38 | Correct | 148 ms | 18888 KB | Output is correct |
39 | Correct | 168 ms | 18936 KB | Output is correct |
40 | Correct | 171 ms | 18912 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 2 ms | 300 KB | Output is correct |
7 | Correct | 2 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 656 ms | 15120 KB | Output is correct |
12 | Correct | 641 ms | 14876 KB | Output is correct |
13 | Correct | 633 ms | 13992 KB | Output is correct |
14 | Correct | 656 ms | 13980 KB | Output is correct |
15 | Correct | 628 ms | 15136 KB | Output is correct |
16 | Correct | 660 ms | 14276 KB | Output is correct |
17 | Correct | 675 ms | 14240 KB | Output is correct |
18 | Correct | 527 ms | 16104 KB | Output is correct |
19 | Correct | 608 ms | 13008 KB | Output is correct |
20 | Correct | 618 ms | 14704 KB | Output is correct |
21 | Correct | 740 ms | 18096 KB | Output is correct |
22 | Correct | 775 ms | 18320 KB | Output is correct |
23 | Correct | 822 ms | 17376 KB | Output is correct |
24 | Correct | 889 ms | 17188 KB | Output is correct |
25 | Correct | 768 ms | 19064 KB | Output is correct |
26 | Correct | 855 ms | 17648 KB | Output is correct |
27 | Correct | 849 ms | 17564 KB | Output is correct |
28 | Correct | 667 ms | 20052 KB | Output is correct |
29 | Correct | 797 ms | 16288 KB | Output is correct |
30 | Correct | 802 ms | 18392 KB | Output is correct |
31 | Correct | 854 ms | 18088 KB | Output is correct |
32 | Correct | 877 ms | 18176 KB | Output is correct |
33 | Correct | 756 ms | 17004 KB | Output is correct |
34 | Correct | 840 ms | 17136 KB | Output is correct |
35 | Correct | 860 ms | 17724 KB | Output is correct |
36 | Correct | 679 ms | 16276 KB | Output is correct |
37 | Correct | 815 ms | 18060 KB | Output is correct |
38 | Correct | 738 ms | 16216 KB | Output is correct |
39 | Correct | 872 ms | 17252 KB | Output is correct |
40 | Correct | 798 ms | 17160 KB | Output is correct |
41 | Correct | 138 ms | 19092 KB | Output is correct |
42 | Correct | 143 ms | 18864 KB | Output is correct |
43 | Correct | 137 ms | 18796 KB | Output is correct |
44 | Correct | 144 ms | 18836 KB | Output is correct |
45 | Correct | 163 ms | 19196 KB | Output is correct |
46 | Correct | 152 ms | 18904 KB | Output is correct |
47 | Correct | 162 ms | 18884 KB | Output is correct |
48 | Correct | 164 ms | 19092 KB | Output is correct |
49 | Correct | 136 ms | 18840 KB | Output is correct |
50 | Correct | 135 ms | 18928 KB | Output is correct |
51 | Correct | 172 ms | 18872 KB | Output is correct |
52 | Correct | 161 ms | 19116 KB | Output is correct |
53 | Correct | 126 ms | 18844 KB | Output is correct |
54 | Correct | 156 ms | 18968 KB | Output is correct |
55 | Correct | 166 ms | 18912 KB | Output is correct |
56 | Correct | 125 ms | 18760 KB | Output is correct |
57 | Correct | 138 ms | 18892 KB | Output is correct |
58 | Correct | 140 ms | 18752 KB | Output is correct |
59 | Correct | 145 ms | 18816 KB | Output is correct |
60 | Correct | 152 ms | 18892 KB | Output is correct |
61 | Correct | 153 ms | 18828 KB | Output is correct |
62 | Correct | 167 ms | 18880 KB | Output is correct |
63 | Correct | 179 ms | 18848 KB | Output is correct |
64 | Correct | 143 ms | 18724 KB | Output is correct |
65 | Correct | 162 ms | 18984 KB | Output is correct |
66 | Correct | 159 ms | 18892 KB | Output is correct |
67 | Correct | 168 ms | 18888 KB | Output is correct |
68 | Correct | 148 ms | 18888 KB | Output is correct |
69 | Correct | 168 ms | 18936 KB | Output is correct |
70 | Correct | 171 ms | 18912 KB | Output is correct |
71 | Correct | 1240 ms | 43272 KB | Output is correct |
72 | Correct | 1364 ms | 43392 KB | Output is correct |
73 | Correct | 1481 ms | 41900 KB | Output is correct |
74 | Correct | 1789 ms | 42432 KB | Output is correct |
75 | Correct | 1425 ms | 44328 KB | Output is correct |
76 | Correct | 1872 ms | 42560 KB | Output is correct |
77 | Correct | 1771 ms | 42460 KB | Output is correct |
78 | Correct | 1030 ms | 46300 KB | Output is correct |
79 | Correct | 1248 ms | 40236 KB | Output is correct |
80 | Correct | 1237 ms | 43520 KB | Output is correct |
81 | Correct | 1514 ms | 43372 KB | Output is correct |
82 | Correct | 1670 ms | 42200 KB | Output is correct |
83 | Correct | 1261 ms | 41428 KB | Output is correct |
84 | Correct | 1869 ms | 42316 KB | Output is correct |
85 | Correct | 1791 ms | 42456 KB | Output is correct |
86 | Correct | 1038 ms | 40284 KB | Output is correct |
87 | Correct | 1400 ms | 43512 KB | Output is correct |
88 | Correct | 1286 ms | 40340 KB | Output is correct |
89 | Correct | 1477 ms | 41900 KB | Output is correct |
90 | Correct | 1522 ms | 42324 KB | Output is correct |
91 | Correct | 1275 ms | 41420 KB | Output is correct |
92 | Correct | 1910 ms | 42476 KB | Output is correct |
93 | Correct | 1774 ms | 42456 KB | Output is correct |
94 | Correct | 1113 ms | 40224 KB | Output is correct |
95 | Correct | 1626 ms | 42352 KB | Output is correct |
96 | Correct | 1620 ms | 42308 KB | Output is correct |
97 | Correct | 1619 ms | 42328 KB | Output is correct |
98 | Correct | 1633 ms | 42308 KB | Output is correct |
99 | Correct | 1599 ms | 42340 KB | Output is correct |
100 | Correct | 1534 ms | 42388 KB | Output is correct |