# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
698925 | 2023-02-14T20:28:04 Z | finn__ | Snake Escaping (JOI18_snake_escaping) | C++17 | 758 ms | 43212 KB |
#include <bits/stdc++.h> using namespace std; #define popcount(x) __builtin_popcount(x) char snakes[1 << 20]; unsigned v[1 << 20], super[1 << 20], sub[1 << 20]; int main() { size_t l, q; scanf("%zu %zu %s", &l, &q, snakes); for (unsigned i = 0; i < 1U << l; i++) super[i] = sub[i] = v[i] = snakes[i] - '0'; for (unsigned i = 0; i < l; i++) for (unsigned j = 0; j < 1U << l; j++) if (j & (1 << i)) sub[j] += sub[j ^ (1 << i)]; else super[j] += super[j ^ (1 << i)]; char s[20]; while (q--) { scanf("%s", s); unsigned a = 0, b = 0, c = 0, ans = 0; for (unsigned i = 0; i < l; i++) { a <<= 1, b <<= 1, c <<= 1; a |= s[i] == '0', b |= s[i] == '1', c |= s[i] == '?'; } if (popcount(a) <= popcount(b) && popcount(a) <= popcount(c)) { ans = super[b]; for (unsigned i = a; i; i = (i - 1) & a) ans += super[b | i] * ((popcount(i) & 1) ? -1 : 1); } else if (popcount(b) <= popcount(a) && popcount(b) <= popcount(c)) { ans = sub[c | b]; for (unsigned i = b; i; i = (i - 1) & b) ans += sub[c | (b ^ i)] * ((popcount(i) & 1) ? -1 : 1); } else { ans = v[b]; for (unsigned i = c; i; i = (i - 1) & c) ans += v[b | i]; } printf("%u\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 320 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 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 | 312 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 320 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 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 | 312 KB | Output is correct |
11 | Correct | 204 ms | 15088 KB | Output is correct |
12 | Correct | 203 ms | 14748 KB | Output is correct |
13 | Correct | 205 ms | 13920 KB | Output is correct |
14 | Correct | 218 ms | 13956 KB | Output is correct |
15 | Correct | 209 ms | 15044 KB | Output is correct |
16 | Correct | 219 ms | 14224 KB | Output is correct |
17 | Correct | 214 ms | 14208 KB | Output is correct |
18 | Correct | 195 ms | 16076 KB | Output is correct |
19 | Correct | 191 ms | 13024 KB | Output is correct |
20 | Correct | 197 ms | 14656 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 320 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 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 | 312 KB | Output is correct |
11 | Correct | 204 ms | 15088 KB | Output is correct |
12 | Correct | 203 ms | 14748 KB | Output is correct |
13 | Correct | 205 ms | 13920 KB | Output is correct |
14 | Correct | 218 ms | 13956 KB | Output is correct |
15 | Correct | 209 ms | 15044 KB | Output is correct |
16 | Correct | 219 ms | 14224 KB | Output is correct |
17 | Correct | 214 ms | 14208 KB | Output is correct |
18 | Correct | 195 ms | 16076 KB | Output is correct |
19 | Correct | 191 ms | 13024 KB | Output is correct |
20 | Correct | 197 ms | 14656 KB | Output is correct |
21 | Correct | 220 ms | 18072 KB | Output is correct |
22 | Correct | 215 ms | 18272 KB | Output is correct |
23 | Correct | 230 ms | 17360 KB | Output is correct |
24 | Correct | 273 ms | 17088 KB | Output is correct |
25 | Correct | 231 ms | 19096 KB | Output is correct |
26 | Correct | 268 ms | 17512 KB | Output is correct |
27 | Correct | 248 ms | 17512 KB | Output is correct |
28 | Correct | 217 ms | 20032 KB | Output is correct |
29 | Correct | 206 ms | 16056 KB | Output is correct |
30 | Correct | 217 ms | 18212 KB | Output is correct |
31 | Correct | 238 ms | 18108 KB | Output is correct |
32 | Correct | 286 ms | 18248 KB | Output is correct |
33 | Correct | 231 ms | 16932 KB | Output is correct |
34 | Correct | 260 ms | 17208 KB | Output is correct |
35 | Correct | 250 ms | 17484 KB | Output is correct |
36 | Correct | 203 ms | 16072 KB | Output is correct |
37 | Correct | 207 ms | 18120 KB | Output is correct |
38 | Correct | 207 ms | 15984 KB | Output is correct |
39 | Correct | 228 ms | 17224 KB | Output is correct |
40 | Correct | 270 ms | 17052 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 320 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 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 | 312 KB | Output is correct |
11 | Correct | 41 ms | 15820 KB | Output is correct |
12 | Correct | 43 ms | 15892 KB | Output is correct |
13 | Correct | 47 ms | 15792 KB | Output is correct |
14 | Correct | 58 ms | 15864 KB | Output is correct |
15 | Correct | 44 ms | 15876 KB | Output is correct |
16 | Correct | 66 ms | 15852 KB | Output is correct |
17 | Correct | 60 ms | 15880 KB | Output is correct |
18 | Correct | 40 ms | 15976 KB | Output is correct |
19 | Correct | 41 ms | 15768 KB | Output is correct |
20 | Correct | 45 ms | 15848 KB | Output is correct |
21 | Correct | 48 ms | 15908 KB | Output is correct |
22 | Correct | 58 ms | 15856 KB | Output is correct |
23 | Correct | 55 ms | 15776 KB | Output is correct |
24 | Correct | 63 ms | 15796 KB | Output is correct |
25 | Correct | 62 ms | 15792 KB | Output is correct |
26 | Correct | 40 ms | 15812 KB | Output is correct |
27 | Correct | 40 ms | 15804 KB | Output is correct |
28 | Correct | 41 ms | 15716 KB | Output is correct |
29 | Correct | 51 ms | 15840 KB | Output is correct |
30 | Correct | 47 ms | 15780 KB | Output is correct |
31 | Correct | 44 ms | 15816 KB | Output is correct |
32 | Correct | 72 ms | 15800 KB | Output is correct |
33 | Correct | 59 ms | 15840 KB | Output is correct |
34 | Correct | 45 ms | 15748 KB | Output is correct |
35 | Correct | 60 ms | 15824 KB | Output is correct |
36 | Correct | 55 ms | 15888 KB | Output is correct |
37 | Correct | 55 ms | 15776 KB | Output is correct |
38 | Correct | 53 ms | 15820 KB | Output is correct |
39 | Correct | 52 ms | 15780 KB | Output is correct |
40 | Correct | 54 ms | 15780 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 320 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 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 | 312 KB | Output is correct |
11 | Correct | 204 ms | 15088 KB | Output is correct |
12 | Correct | 203 ms | 14748 KB | Output is correct |
13 | Correct | 205 ms | 13920 KB | Output is correct |
14 | Correct | 218 ms | 13956 KB | Output is correct |
15 | Correct | 209 ms | 15044 KB | Output is correct |
16 | Correct | 219 ms | 14224 KB | Output is correct |
17 | Correct | 214 ms | 14208 KB | Output is correct |
18 | Correct | 195 ms | 16076 KB | Output is correct |
19 | Correct | 191 ms | 13024 KB | Output is correct |
20 | Correct | 197 ms | 14656 KB | Output is correct |
21 | Correct | 220 ms | 18072 KB | Output is correct |
22 | Correct | 215 ms | 18272 KB | Output is correct |
23 | Correct | 230 ms | 17360 KB | Output is correct |
24 | Correct | 273 ms | 17088 KB | Output is correct |
25 | Correct | 231 ms | 19096 KB | Output is correct |
26 | Correct | 268 ms | 17512 KB | Output is correct |
27 | Correct | 248 ms | 17512 KB | Output is correct |
28 | Correct | 217 ms | 20032 KB | Output is correct |
29 | Correct | 206 ms | 16056 KB | Output is correct |
30 | Correct | 217 ms | 18212 KB | Output is correct |
31 | Correct | 238 ms | 18108 KB | Output is correct |
32 | Correct | 286 ms | 18248 KB | Output is correct |
33 | Correct | 231 ms | 16932 KB | Output is correct |
34 | Correct | 260 ms | 17208 KB | Output is correct |
35 | Correct | 250 ms | 17484 KB | Output is correct |
36 | Correct | 203 ms | 16072 KB | Output is correct |
37 | Correct | 207 ms | 18120 KB | Output is correct |
38 | Correct | 207 ms | 15984 KB | Output is correct |
39 | Correct | 228 ms | 17224 KB | Output is correct |
40 | Correct | 270 ms | 17052 KB | Output is correct |
41 | Correct | 41 ms | 15820 KB | Output is correct |
42 | Correct | 43 ms | 15892 KB | Output is correct |
43 | Correct | 47 ms | 15792 KB | Output is correct |
44 | Correct | 58 ms | 15864 KB | Output is correct |
45 | Correct | 44 ms | 15876 KB | Output is correct |
46 | Correct | 66 ms | 15852 KB | Output is correct |
47 | Correct | 60 ms | 15880 KB | Output is correct |
48 | Correct | 40 ms | 15976 KB | Output is correct |
49 | Correct | 41 ms | 15768 KB | Output is correct |
50 | Correct | 45 ms | 15848 KB | Output is correct |
51 | Correct | 48 ms | 15908 KB | Output is correct |
52 | Correct | 58 ms | 15856 KB | Output is correct |
53 | Correct | 55 ms | 15776 KB | Output is correct |
54 | Correct | 63 ms | 15796 KB | Output is correct |
55 | Correct | 62 ms | 15792 KB | Output is correct |
56 | Correct | 40 ms | 15812 KB | Output is correct |
57 | Correct | 40 ms | 15804 KB | Output is correct |
58 | Correct | 41 ms | 15716 KB | Output is correct |
59 | Correct | 51 ms | 15840 KB | Output is correct |
60 | Correct | 47 ms | 15780 KB | Output is correct |
61 | Correct | 44 ms | 15816 KB | Output is correct |
62 | Correct | 72 ms | 15800 KB | Output is correct |
63 | Correct | 59 ms | 15840 KB | Output is correct |
64 | Correct | 45 ms | 15748 KB | Output is correct |
65 | Correct | 60 ms | 15824 KB | Output is correct |
66 | Correct | 55 ms | 15888 KB | Output is correct |
67 | Correct | 55 ms | 15776 KB | Output is correct |
68 | Correct | 53 ms | 15820 KB | Output is correct |
69 | Correct | 52 ms | 15780 KB | Output is correct |
70 | Correct | 54 ms | 15780 KB | Output is correct |
71 | Correct | 315 ms | 40216 KB | Output is correct |
72 | Correct | 326 ms | 40360 KB | Output is correct |
73 | Correct | 428 ms | 38912 KB | Output is correct |
74 | Correct | 631 ms | 39120 KB | Output is correct |
75 | Correct | 342 ms | 41268 KB | Output is correct |
76 | Correct | 641 ms | 39496 KB | Output is correct |
77 | Correct | 642 ms | 39296 KB | Output is correct |
78 | Correct | 301 ms | 43212 KB | Output is correct |
79 | Correct | 319 ms | 37144 KB | Output is correct |
80 | Correct | 323 ms | 40336 KB | Output is correct |
81 | Correct | 441 ms | 40212 KB | Output is correct |
82 | Correct | 566 ms | 39200 KB | Output is correct |
83 | Correct | 339 ms | 38436 KB | Output is correct |
84 | Correct | 744 ms | 39332 KB | Output is correct |
85 | Correct | 650 ms | 39528 KB | Output is correct |
86 | Correct | 288 ms | 37088 KB | Output is correct |
87 | Correct | 310 ms | 40168 KB | Output is correct |
88 | Correct | 325 ms | 37152 KB | Output is correct |
89 | Correct | 432 ms | 38932 KB | Output is correct |
90 | Correct | 387 ms | 39104 KB | Output is correct |
91 | Correct | 337 ms | 38380 KB | Output is correct |
92 | Correct | 758 ms | 39516 KB | Output is correct |
93 | Correct | 641 ms | 39356 KB | Output is correct |
94 | Correct | 293 ms | 37220 KB | Output is correct |
95 | Correct | 552 ms | 39240 KB | Output is correct |
96 | Correct | 549 ms | 39192 KB | Output is correct |
97 | Correct | 563 ms | 39240 KB | Output is correct |
98 | Correct | 562 ms | 39184 KB | Output is correct |
99 | Correct | 557 ms | 39200 KB | Output is correct |
100 | Correct | 576 ms | 39220 KB | Output is correct |