# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
160817 | 2019-10-30T03:48:09 Z | combi1k1 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1085 ms | 40512 KB |
#include<bits/stdc++.h> using namespace std; int8_t c[1 << 20]; string s; int f0[1 << 20]; int f1[1 << 20]; int work() { int m0 = 0; int m1 = 0; int m2 = 0; int L = s.size(); reverse(s.begin(),s.end()); for(int i = 0 ; i < L ; ++i) { if (s[i] == '0') m0 |= (1 << i); if (s[i] == '1') m1 |= (1 << i); if (s[i] == '?') m2 |= (1 << i); } if (__builtin_popcount(m0) <= L / 3) { int ans = f1[m1]; for(int x = m0 ; x ; x = (x - 1) & m0) { if (__builtin_popcount(x) & 1) ans -= f1[m1 | x]; else ans += f1[m1 | x]; } return ans; } if (__builtin_popcount(m1) <= L / 3) { int ans = f0[m0]; for(int x = m1 ; x ; x = (x - 1) & m1) { if (__builtin_popcount(x) & 1) ans -= f0[m0 | x]; else ans += f0[m0 | x]; } return ans; } if (__builtin_popcount(m2) <= L / 3) { int ans = c[m1]; for(int x = m2 ; x ; x = (x - 1) & m2) ans += c[m1 | x]; return ans; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int q; cin >> q; int m = (1 << n); cin >> s; for(int i = 0 ; i < m ; ++i) f0[m - i - 1] = f1[i] = c[i] = s[i] - '0'; for(int i = 0 ; i < n ; ++i) for(int j = 0 ; j < m ; ++j) if (j >> i & 1) f0[j ^ (1 << i)] += f0[j], f1[j ^ (1 << i)] += f1[j]; for(int i = 0 ; i < q ; ++i) { cin >> s; cout << work() << "\n"; } } /* 4 8 3141592653589793 0101 ?01? ??1? ?0?? 1?00 01?1 ??10 ???? */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 424 KB | Output is correct |
11 | Correct | 249 ms | 15096 KB | Output is correct |
12 | Correct | 280 ms | 14944 KB | Output is correct |
13 | Correct | 314 ms | 14080 KB | Output is correct |
14 | Correct | 333 ms | 14456 KB | Output is correct |
15 | Correct | 322 ms | 15196 KB | Output is correct |
16 | Correct | 333 ms | 14404 KB | Output is correct |
17 | Correct | 331 ms | 14472 KB | Output is correct |
18 | Correct | 213 ms | 16120 KB | Output is correct |
19 | Correct | 257 ms | 13108 KB | Output is correct |
20 | Correct | 271 ms | 14840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 424 KB | Output is correct |
11 | Correct | 249 ms | 15096 KB | Output is correct |
12 | Correct | 280 ms | 14944 KB | Output is correct |
13 | Correct | 314 ms | 14080 KB | Output is correct |
14 | Correct | 333 ms | 14456 KB | Output is correct |
15 | Correct | 322 ms | 15196 KB | Output is correct |
16 | Correct | 333 ms | 14404 KB | Output is correct |
17 | Correct | 331 ms | 14472 KB | Output is correct |
18 | Correct | 213 ms | 16120 KB | Output is correct |
19 | Correct | 257 ms | 13108 KB | Output is correct |
20 | Correct | 271 ms | 14840 KB | Output is correct |
21 | Correct | 288 ms | 18196 KB | Output is correct |
22 | Correct | 317 ms | 18296 KB | Output is correct |
23 | Correct | 397 ms | 17456 KB | Output is correct |
24 | Correct | 540 ms | 17412 KB | Output is correct |
25 | Correct | 346 ms | 19204 KB | Output is correct |
26 | Correct | 413 ms | 17712 KB | Output is correct |
27 | Correct | 424 ms | 17780 KB | Output is correct |
28 | Correct | 231 ms | 20344 KB | Output is correct |
29 | Correct | 291 ms | 16092 KB | Output is correct |
30 | Correct | 310 ms | 18424 KB | Output is correct |
31 | Correct | 367 ms | 18168 KB | Output is correct |
32 | Correct | 414 ms | 18284 KB | Output is correct |
33 | Correct | 329 ms | 17276 KB | Output is correct |
34 | Correct | 391 ms | 17248 KB | Output is correct |
35 | Correct | 390 ms | 17724 KB | Output is correct |
36 | Correct | 227 ms | 16220 KB | Output is correct |
37 | Correct | 299 ms | 18328 KB | Output is correct |
38 | Correct | 328 ms | 16248 KB | Output is correct |
39 | Correct | 364 ms | 17272 KB | Output is correct |
40 | Correct | 392 ms | 17344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 424 KB | Output is correct |
11 | Correct | 66 ms | 13080 KB | Output is correct |
12 | Correct | 68 ms | 13080 KB | Output is correct |
13 | Correct | 85 ms | 13052 KB | Output is correct |
14 | Correct | 95 ms | 13000 KB | Output is correct |
15 | Correct | 80 ms | 13076 KB | Output is correct |
16 | Correct | 89 ms | 13080 KB | Output is correct |
17 | Correct | 92 ms | 13084 KB | Output is correct |
18 | Correct | 60 ms | 13184 KB | Output is correct |
19 | Correct | 67 ms | 12956 KB | Output is correct |
20 | Correct | 69 ms | 13080 KB | Output is correct |
21 | Correct | 76 ms | 13076 KB | Output is correct |
22 | Correct | 90 ms | 13052 KB | Output is correct |
23 | Correct | 71 ms | 12924 KB | Output is correct |
24 | Correct | 93 ms | 13032 KB | Output is correct |
25 | Correct | 99 ms | 13088 KB | Output is correct |
26 | Correct | 63 ms | 12964 KB | Output is correct |
27 | Correct | 66 ms | 13080 KB | Output is correct |
28 | Correct | 73 ms | 12952 KB | Output is correct |
29 | Correct | 77 ms | 12952 KB | Output is correct |
30 | Correct | 74 ms | 13080 KB | Output is correct |
31 | Correct | 73 ms | 13080 KB | Output is correct |
32 | Correct | 95 ms | 13208 KB | Output is correct |
33 | Correct | 91 ms | 13080 KB | Output is correct |
34 | Correct | 58 ms | 12824 KB | Output is correct |
35 | Correct | 78 ms | 13080 KB | Output is correct |
36 | Correct | 77 ms | 13080 KB | Output is correct |
37 | Correct | 100 ms | 13000 KB | Output is correct |
38 | Correct | 84 ms | 12952 KB | Output is correct |
39 | Correct | 86 ms | 13156 KB | Output is correct |
40 | Correct | 81 ms | 12952 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 424 KB | Output is correct |
11 | Correct | 249 ms | 15096 KB | Output is correct |
12 | Correct | 280 ms | 14944 KB | Output is correct |
13 | Correct | 314 ms | 14080 KB | Output is correct |
14 | Correct | 333 ms | 14456 KB | Output is correct |
15 | Correct | 322 ms | 15196 KB | Output is correct |
16 | Correct | 333 ms | 14404 KB | Output is correct |
17 | Correct | 331 ms | 14472 KB | Output is correct |
18 | Correct | 213 ms | 16120 KB | Output is correct |
19 | Correct | 257 ms | 13108 KB | Output is correct |
20 | Correct | 271 ms | 14840 KB | Output is correct |
21 | Correct | 288 ms | 18196 KB | Output is correct |
22 | Correct | 317 ms | 18296 KB | Output is correct |
23 | Correct | 397 ms | 17456 KB | Output is correct |
24 | Correct | 540 ms | 17412 KB | Output is correct |
25 | Correct | 346 ms | 19204 KB | Output is correct |
26 | Correct | 413 ms | 17712 KB | Output is correct |
27 | Correct | 424 ms | 17780 KB | Output is correct |
28 | Correct | 231 ms | 20344 KB | Output is correct |
29 | Correct | 291 ms | 16092 KB | Output is correct |
30 | Correct | 310 ms | 18424 KB | Output is correct |
31 | Correct | 367 ms | 18168 KB | Output is correct |
32 | Correct | 414 ms | 18284 KB | Output is correct |
33 | Correct | 329 ms | 17276 KB | Output is correct |
34 | Correct | 391 ms | 17248 KB | Output is correct |
35 | Correct | 390 ms | 17724 KB | Output is correct |
36 | Correct | 227 ms | 16220 KB | Output is correct |
37 | Correct | 299 ms | 18328 KB | Output is correct |
38 | Correct | 328 ms | 16248 KB | Output is correct |
39 | Correct | 364 ms | 17272 KB | Output is correct |
40 | Correct | 392 ms | 17344 KB | Output is correct |
41 | Correct | 66 ms | 13080 KB | Output is correct |
42 | Correct | 68 ms | 13080 KB | Output is correct |
43 | Correct | 85 ms | 13052 KB | Output is correct |
44 | Correct | 95 ms | 13000 KB | Output is correct |
45 | Correct | 80 ms | 13076 KB | Output is correct |
46 | Correct | 89 ms | 13080 KB | Output is correct |
47 | Correct | 92 ms | 13084 KB | Output is correct |
48 | Correct | 60 ms | 13184 KB | Output is correct |
49 | Correct | 67 ms | 12956 KB | Output is correct |
50 | Correct | 69 ms | 13080 KB | Output is correct |
51 | Correct | 76 ms | 13076 KB | Output is correct |
52 | Correct | 90 ms | 13052 KB | Output is correct |
53 | Correct | 71 ms | 12924 KB | Output is correct |
54 | Correct | 93 ms | 13032 KB | Output is correct |
55 | Correct | 99 ms | 13088 KB | Output is correct |
56 | Correct | 63 ms | 12964 KB | Output is correct |
57 | Correct | 66 ms | 13080 KB | Output is correct |
58 | Correct | 73 ms | 12952 KB | Output is correct |
59 | Correct | 77 ms | 12952 KB | Output is correct |
60 | Correct | 74 ms | 13080 KB | Output is correct |
61 | Correct | 73 ms | 13080 KB | Output is correct |
62 | Correct | 95 ms | 13208 KB | Output is correct |
63 | Correct | 91 ms | 13080 KB | Output is correct |
64 | Correct | 58 ms | 12824 KB | Output is correct |
65 | Correct | 78 ms | 13080 KB | Output is correct |
66 | Correct | 77 ms | 13080 KB | Output is correct |
67 | Correct | 100 ms | 13000 KB | Output is correct |
68 | Correct | 84 ms | 12952 KB | Output is correct |
69 | Correct | 86 ms | 13156 KB | Output is correct |
70 | Correct | 81 ms | 12952 KB | Output is correct |
71 | Correct | 589 ms | 35868 KB | Output is correct |
72 | Correct | 568 ms | 37536 KB | Output is correct |
73 | Correct | 682 ms | 36144 KB | Output is correct |
74 | Correct | 849 ms | 36372 KB | Output is correct |
75 | Correct | 512 ms | 38424 KB | Output is correct |
76 | Correct | 872 ms | 36700 KB | Output is correct |
77 | Correct | 952 ms | 36660 KB | Output is correct |
78 | Correct | 340 ms | 40512 KB | Output is correct |
79 | Correct | 589 ms | 34552 KB | Output is correct |
80 | Correct | 506 ms | 37628 KB | Output is correct |
81 | Correct | 697 ms | 37304 KB | Output is correct |
82 | Correct | 926 ms | 36380 KB | Output is correct |
83 | Correct | 511 ms | 35712 KB | Output is correct |
84 | Correct | 981 ms | 36352 KB | Output is correct |
85 | Correct | 1044 ms | 36584 KB | Output is correct |
86 | Correct | 280 ms | 34392 KB | Output is correct |
87 | Correct | 467 ms | 37368 KB | Output is correct |
88 | Correct | 489 ms | 34252 KB | Output is correct |
89 | Correct | 661 ms | 36084 KB | Output is correct |
90 | Correct | 578 ms | 36336 KB | Output is correct |
91 | Correct | 558 ms | 35524 KB | Output is correct |
92 | Correct | 1070 ms | 36740 KB | Output is correct |
93 | Correct | 1085 ms | 36644 KB | Output is correct |
94 | Correct | 308 ms | 34348 KB | Output is correct |
95 | Correct | 860 ms | 36336 KB | Output is correct |
96 | Correct | 926 ms | 36448 KB | Output is correct |
97 | Correct | 866 ms | 36316 KB | Output is correct |
98 | Correct | 1016 ms | 36400 KB | Output is correct |
99 | Correct | 831 ms | 36568 KB | Output is correct |
100 | Correct | 905 ms | 36436 KB | Output is correct |