# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101827 | 2019-03-20T12:13:35 Z | KCSC | Snake Escaping (JOI18_snake_escaping) | C++14 | 1161 ms | 43076 KB |
#include <bits/stdc++.h> using namespace std; const int DIM = 20; char str[1 << DIM], aux[DIM]; int udp[1 << DIM], ddp[1 << DIM], cbit[1 << DIM]; int main(void) { #ifdef HOME freopen("snake.in", "r", stdin); freopen("snake.out", "w", stdout); #endif int n, q; scanf("%d %d\n%s\n", &n, &q, str); for (int msk = 0; msk < (1 << n); ++msk) { cbit[msk] = cbit[msk >> 1] + (msk & 1); udp[msk] = ddp[msk] = str[msk] - '0'; } for (int b = 0; b < n; ++b) { for (int msk = 0; msk < (1 << n); ++msk) { if (msk & (1 << b)) { udp[msk ^ (1 << b)] += udp[msk]; } else { ddp[msk ^ (1 << b)] += ddp[msk]; } } } while (q--) { int msk0 = 0, msk1 = 0, mskq = 0; scanf("%s\n", aux); reverse(aux, aux + n); for (int i = 0; i < n; ++i) { if (aux[i] == '0') { msk0 ^= (1 << i); } if (aux[i] == '1') { msk1 ^= (1 << i); } if (aux[i] == '?') { mskq ^= (1 << i); } } int ans = 0; if (cbit[mskq] <= 7) { for (int axm = mskq, nr = (1 << cbit[mskq]); nr; (--axm) &= mskq, --nr) { ans += str[axm ^ msk1] - '0'; } } else if (cbit[msk0] <= 7) { for (int axm = msk0, nr = (1 << cbit[msk0]); nr; (--axm) &= msk0, --nr) { ans += udp[msk1 ^ axm] * ((cbit[axm] & 1) ? -1 : 1); } } else if (cbit[msk1] <= 7) { for (int axm = msk1, nr = (1 << cbit[msk1]); nr; (--axm) &= msk1, --nr) { ans += ddp[mskq ^ msk1 ^ axm] * ((cbit[axm] & 1) ? -1 : 1); } } printf("%d\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 317 ms | 4272 KB | Output is correct |
12 | Correct | 343 ms | 14808 KB | Output is correct |
13 | Correct | 326 ms | 14096 KB | Output is correct |
14 | Correct | 292 ms | 14216 KB | Output is correct |
15 | Correct | 384 ms | 15108 KB | Output is correct |
16 | Correct | 321 ms | 14200 KB | Output is correct |
17 | Correct | 316 ms | 14440 KB | Output is correct |
18 | Correct | 231 ms | 15992 KB | Output is correct |
19 | Correct | 257 ms | 13176 KB | Output is correct |
20 | Correct | 359 ms | 14712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 317 ms | 4272 KB | Output is correct |
12 | Correct | 343 ms | 14808 KB | Output is correct |
13 | Correct | 326 ms | 14096 KB | Output is correct |
14 | Correct | 292 ms | 14216 KB | Output is correct |
15 | Correct | 384 ms | 15108 KB | Output is correct |
16 | Correct | 321 ms | 14200 KB | Output is correct |
17 | Correct | 316 ms | 14440 KB | Output is correct |
18 | Correct | 231 ms | 15992 KB | Output is correct |
19 | Correct | 257 ms | 13176 KB | Output is correct |
20 | Correct | 359 ms | 14712 KB | Output is correct |
21 | Correct | 491 ms | 18100 KB | Output is correct |
22 | Correct | 435 ms | 18392 KB | Output is correct |
23 | Correct | 401 ms | 17276 KB | Output is correct |
24 | Correct | 367 ms | 17144 KB | Output is correct |
25 | Correct | 390 ms | 19144 KB | Output is correct |
26 | Correct | 432 ms | 17656 KB | Output is correct |
27 | Correct | 428 ms | 17656 KB | Output is correct |
28 | Correct | 289 ms | 20080 KB | Output is correct |
29 | Correct | 394 ms | 16144 KB | Output is correct |
30 | Correct | 460 ms | 18424 KB | Output is correct |
31 | Correct | 402 ms | 18168 KB | Output is correct |
32 | Correct | 383 ms | 18040 KB | Output is correct |
33 | Correct | 330 ms | 17144 KB | Output is correct |
34 | Correct | 355 ms | 17116 KB | Output is correct |
35 | Correct | 376 ms | 17624 KB | Output is correct |
36 | Correct | 305 ms | 16120 KB | Output is correct |
37 | Correct | 414 ms | 18168 KB | Output is correct |
38 | Correct | 335 ms | 16120 KB | Output is correct |
39 | Correct | 391 ms | 17272 KB | Output is correct |
40 | Correct | 380 ms | 17244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 81 ms | 14172 KB | Output is correct |
12 | Correct | 80 ms | 14320 KB | Output is correct |
13 | Correct | 88 ms | 14240 KB | Output is correct |
14 | Correct | 99 ms | 14204 KB | Output is correct |
15 | Correct | 91 ms | 14328 KB | Output is correct |
16 | Correct | 116 ms | 14300 KB | Output is correct |
17 | Correct | 91 ms | 14276 KB | Output is correct |
18 | Correct | 69 ms | 14456 KB | Output is correct |
19 | Correct | 77 ms | 14208 KB | Output is correct |
20 | Correct | 78 ms | 14332 KB | Output is correct |
21 | Correct | 123 ms | 14376 KB | Output is correct |
22 | Correct | 95 ms | 14388 KB | Output is correct |
23 | Correct | 81 ms | 14328 KB | Output is correct |
24 | Correct | 98 ms | 14328 KB | Output is correct |
25 | Correct | 108 ms | 14364 KB | Output is correct |
26 | Correct | 60 ms | 14200 KB | Output is correct |
27 | Correct | 71 ms | 14328 KB | Output is correct |
28 | Correct | 75 ms | 14200 KB | Output is correct |
29 | Correct | 87 ms | 14328 KB | Output is correct |
30 | Correct | 96 ms | 14328 KB | Output is correct |
31 | Correct | 78 ms | 14204 KB | Output is correct |
32 | Correct | 107 ms | 14328 KB | Output is correct |
33 | Correct | 92 ms | 14328 KB | Output is correct |
34 | Correct | 65 ms | 14200 KB | Output is correct |
35 | Correct | 96 ms | 14268 KB | Output is correct |
36 | Correct | 87 ms | 14200 KB | Output is correct |
37 | Correct | 83 ms | 14328 KB | Output is correct |
38 | Correct | 92 ms | 14328 KB | Output is correct |
39 | Correct | 82 ms | 14328 KB | Output is correct |
40 | Correct | 83 ms | 14304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 317 ms | 4272 KB | Output is correct |
12 | Correct | 343 ms | 14808 KB | Output is correct |
13 | Correct | 326 ms | 14096 KB | Output is correct |
14 | Correct | 292 ms | 14216 KB | Output is correct |
15 | Correct | 384 ms | 15108 KB | Output is correct |
16 | Correct | 321 ms | 14200 KB | Output is correct |
17 | Correct | 316 ms | 14440 KB | Output is correct |
18 | Correct | 231 ms | 15992 KB | Output is correct |
19 | Correct | 257 ms | 13176 KB | Output is correct |
20 | Correct | 359 ms | 14712 KB | Output is correct |
21 | Correct | 491 ms | 18100 KB | Output is correct |
22 | Correct | 435 ms | 18392 KB | Output is correct |
23 | Correct | 401 ms | 17276 KB | Output is correct |
24 | Correct | 367 ms | 17144 KB | Output is correct |
25 | Correct | 390 ms | 19144 KB | Output is correct |
26 | Correct | 432 ms | 17656 KB | Output is correct |
27 | Correct | 428 ms | 17656 KB | Output is correct |
28 | Correct | 289 ms | 20080 KB | Output is correct |
29 | Correct | 394 ms | 16144 KB | Output is correct |
30 | Correct | 460 ms | 18424 KB | Output is correct |
31 | Correct | 402 ms | 18168 KB | Output is correct |
32 | Correct | 383 ms | 18040 KB | Output is correct |
33 | Correct | 330 ms | 17144 KB | Output is correct |
34 | Correct | 355 ms | 17116 KB | Output is correct |
35 | Correct | 376 ms | 17624 KB | Output is correct |
36 | Correct | 305 ms | 16120 KB | Output is correct |
37 | Correct | 414 ms | 18168 KB | Output is correct |
38 | Correct | 335 ms | 16120 KB | Output is correct |
39 | Correct | 391 ms | 17272 KB | Output is correct |
40 | Correct | 380 ms | 17244 KB | Output is correct |
41 | Correct | 81 ms | 14172 KB | Output is correct |
42 | Correct | 80 ms | 14320 KB | Output is correct |
43 | Correct | 88 ms | 14240 KB | Output is correct |
44 | Correct | 99 ms | 14204 KB | Output is correct |
45 | Correct | 91 ms | 14328 KB | Output is correct |
46 | Correct | 116 ms | 14300 KB | Output is correct |
47 | Correct | 91 ms | 14276 KB | Output is correct |
48 | Correct | 69 ms | 14456 KB | Output is correct |
49 | Correct | 77 ms | 14208 KB | Output is correct |
50 | Correct | 78 ms | 14332 KB | Output is correct |
51 | Correct | 123 ms | 14376 KB | Output is correct |
52 | Correct | 95 ms | 14388 KB | Output is correct |
53 | Correct | 81 ms | 14328 KB | Output is correct |
54 | Correct | 98 ms | 14328 KB | Output is correct |
55 | Correct | 108 ms | 14364 KB | Output is correct |
56 | Correct | 60 ms | 14200 KB | Output is correct |
57 | Correct | 71 ms | 14328 KB | Output is correct |
58 | Correct | 75 ms | 14200 KB | Output is correct |
59 | Correct | 87 ms | 14328 KB | Output is correct |
60 | Correct | 96 ms | 14328 KB | Output is correct |
61 | Correct | 78 ms | 14204 KB | Output is correct |
62 | Correct | 107 ms | 14328 KB | Output is correct |
63 | Correct | 92 ms | 14328 KB | Output is correct |
64 | Correct | 65 ms | 14200 KB | Output is correct |
65 | Correct | 96 ms | 14268 KB | Output is correct |
66 | Correct | 87 ms | 14200 KB | Output is correct |
67 | Correct | 83 ms | 14328 KB | Output is correct |
68 | Correct | 92 ms | 14328 KB | Output is correct |
69 | Correct | 82 ms | 14328 KB | Output is correct |
70 | Correct | 83 ms | 14304 KB | Output is correct |
71 | Correct | 640 ms | 40108 KB | Output is correct |
72 | Correct | 782 ms | 40444 KB | Output is correct |
73 | Correct | 701 ms | 38832 KB | Output is correct |
74 | Correct | 855 ms | 39288 KB | Output is correct |
75 | Correct | 660 ms | 41152 KB | Output is correct |
76 | Correct | 1020 ms | 39584 KB | Output is correct |
77 | Correct | 968 ms | 39348 KB | Output is correct |
78 | Correct | 419 ms | 43076 KB | Output is correct |
79 | Correct | 457 ms | 37276 KB | Output is correct |
80 | Correct | 697 ms | 40264 KB | Output is correct |
81 | Correct | 1063 ms | 40228 KB | Output is correct |
82 | Correct | 887 ms | 39184 KB | Output is correct |
83 | Correct | 565 ms | 38364 KB | Output is correct |
84 | Correct | 677 ms | 39180 KB | Output is correct |
85 | Correct | 938 ms | 39364 KB | Output is correct |
86 | Correct | 322 ms | 37244 KB | Output is correct |
87 | Correct | 660 ms | 40176 KB | Output is correct |
88 | Correct | 523 ms | 37220 KB | Output is correct |
89 | Correct | 726 ms | 38856 KB | Output is correct |
90 | Correct | 671 ms | 39160 KB | Output is correct |
91 | Correct | 500 ms | 38320 KB | Output is correct |
92 | Correct | 976 ms | 39612 KB | Output is correct |
93 | Correct | 1161 ms | 39656 KB | Output is correct |
94 | Correct | 378 ms | 37216 KB | Output is correct |
95 | Correct | 873 ms | 39416 KB | Output is correct |
96 | Correct | 871 ms | 39376 KB | Output is correct |
97 | Correct | 923 ms | 39388 KB | Output is correct |
98 | Correct | 876 ms | 39388 KB | Output is correct |
99 | Correct | 701 ms | 39416 KB | Output is correct |
100 | Correct | 803 ms | 39292 KB | Output is correct |