# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
944361 | 2024-03-12T15:50:30 Z | guechotjrhh | Snake Escaping (JOI18_snake_escaping) | C++14 | 729 ms | 46344 KB |
#include<iostream> #include<string> using namespace std; #include<string> #include<vector> #include<algorithm> #define maxp 1048580 using namespace std; int st[maxp],n,p,zer[maxp], on[maxp], cnt[maxp]; int ab(int x) { return x > 0 ? x : -x; } void init(int N, int Q, char*S){ n=N; p= 1<<n; for (int i = 0; i < p; i++) zer[i] = on[i] = st[i] = S[i] - '0'; for (int i = 1; i < p; i<<=1) { for (int j = 0; j < p; j++) { if (j & i) zer[j] += zer[j ^ i]; else on[j] += on[j ^ i]; } } cnt[0] = 0; for (int i = 0; i < p/2; i++) { cnt[i << 1] = cnt[i]; cnt[(i << 1) + 1] = cnt[i] + 1; } } int query(char* A) { int a = 0, b = 0, q = 0, res=0; for (int i = 0; i < n; i++) { if (A[i] == '0') a|=1<<(n-1-i); else if (A[i] == '1') b |= 1 << (n - 1 - i); else q |= 1 << (n - 1 - i); } int oc = cnt[b], zc = cnt[a], qc = cnt[q]; if (oc < zc && oc < qc) { res = 0; for (int i = b; i >= 0; i--) { i &= b; if (cnt[i | q] & 1) res += zer[i | q]; else res -= zer[i | q]; } res= ab(res); } else if (qc > zc) { res = 0; for (int i = a; i >= 0; i--) { i &= a; if (cnt[i | b] & 1) res += on[i | b]; else res -= on[i | b]; } res= ab(res); } else { res = 0; for (int i = q; i >= 0; i--) { i &= q; res += st[i | b]; } } return res; } /* 4 8 3141592653589793 0101 ?01? ??1? ?0?? 1?00 01?1 ??10 ???? 3 5 12345678 000 0?? 1?0 ?11 ??? */ int main() { ios::sync_with_stdio(0); cin.tie(0); int N, Q; scanf("%d%d", &N, &Q); char S[(1<<N)+1]; scanf("%s", S); init(N, Q, S); for (int i = 0; i < Q; i++) { char A[N+1]; scanf("%s", A); printf("%d\n", query(A)); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6488 KB | Output is correct |
3 | Correct | 2 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6488 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6488 KB | Output is correct |
3 | Correct | 2 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6488 KB | Output is correct |
11 | Correct | 211 ms | 21272 KB | Output is correct |
12 | Correct | 205 ms | 20564 KB | Output is correct |
13 | Correct | 234 ms | 19880 KB | Output is correct |
14 | Correct | 233 ms | 20048 KB | Output is correct |
15 | Correct | 218 ms | 21120 KB | Output is correct |
16 | Correct | 249 ms | 20140 KB | Output is correct |
17 | Correct | 295 ms | 20560 KB | Output is correct |
18 | Correct | 172 ms | 22028 KB | Output is correct |
19 | Correct | 196 ms | 18956 KB | Output is correct |
20 | Correct | 212 ms | 20536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6488 KB | Output is correct |
3 | Correct | 2 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6488 KB | Output is correct |
11 | Correct | 211 ms | 21272 KB | Output is correct |
12 | Correct | 205 ms | 20564 KB | Output is correct |
13 | Correct | 234 ms | 19880 KB | Output is correct |
14 | Correct | 233 ms | 20048 KB | Output is correct |
15 | Correct | 218 ms | 21120 KB | Output is correct |
16 | Correct | 249 ms | 20140 KB | Output is correct |
17 | Correct | 295 ms | 20560 KB | Output is correct |
18 | Correct | 172 ms | 22028 KB | Output is correct |
19 | Correct | 196 ms | 18956 KB | Output is correct |
20 | Correct | 212 ms | 20536 KB | Output is correct |
21 | Correct | 228 ms | 23728 KB | Output is correct |
22 | Correct | 237 ms | 23804 KB | Output is correct |
23 | Correct | 277 ms | 23304 KB | Output is correct |
24 | Correct | 265 ms | 22812 KB | Output is correct |
25 | Correct | 253 ms | 24724 KB | Output is correct |
26 | Correct | 273 ms | 23236 KB | Output is correct |
27 | Correct | 324 ms | 23076 KB | Output is correct |
28 | Correct | 187 ms | 25668 KB | Output is correct |
29 | Correct | 227 ms | 21572 KB | Output is correct |
30 | Correct | 237 ms | 23900 KB | Output is correct |
31 | Correct | 260 ms | 23828 KB | Output is correct |
32 | Correct | 265 ms | 23632 KB | Output is correct |
33 | Correct | 243 ms | 22656 KB | Output is correct |
34 | Correct | 264 ms | 22612 KB | Output is correct |
35 | Correct | 269 ms | 23120 KB | Output is correct |
36 | Correct | 183 ms | 21816 KB | Output is correct |
37 | Correct | 220 ms | 23600 KB | Output is correct |
38 | Correct | 238 ms | 21804 KB | Output is correct |
39 | Correct | 256 ms | 22772 KB | Output is correct |
40 | Correct | 265 ms | 22720 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6488 KB | Output is correct |
3 | Correct | 2 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6488 KB | Output is correct |
11 | Correct | 40 ms | 20136 KB | Output is correct |
12 | Correct | 39 ms | 20052 KB | Output is correct |
13 | Correct | 45 ms | 20052 KB | Output is correct |
14 | Correct | 55 ms | 20044 KB | Output is correct |
15 | Correct | 43 ms | 19988 KB | Output is correct |
16 | Correct | 50 ms | 20052 KB | Output is correct |
17 | Correct | 49 ms | 20052 KB | Output is correct |
18 | Correct | 32 ms | 20156 KB | Output is correct |
19 | Correct | 54 ms | 19792 KB | Output is correct |
20 | Correct | 49 ms | 19992 KB | Output is correct |
21 | Correct | 58 ms | 19980 KB | Output is correct |
22 | Correct | 51 ms | 20012 KB | Output is correct |
23 | Correct | 46 ms | 20016 KB | Output is correct |
24 | Correct | 51 ms | 20028 KB | Output is correct |
25 | Correct | 55 ms | 20024 KB | Output is correct |
26 | Correct | 32 ms | 19988 KB | Output is correct |
27 | Correct | 42 ms | 20164 KB | Output is correct |
28 | Correct | 40 ms | 19804 KB | Output is correct |
29 | Correct | 44 ms | 20052 KB | Output is correct |
30 | Correct | 56 ms | 20052 KB | Output is correct |
31 | Correct | 38 ms | 19976 KB | Output is correct |
32 | Correct | 54 ms | 20080 KB | Output is correct |
33 | Correct | 49 ms | 20012 KB | Output is correct |
34 | Correct | 31 ms | 19796 KB | Output is correct |
35 | Correct | 45 ms | 19900 KB | Output is correct |
36 | Correct | 45 ms | 20048 KB | Output is correct |
37 | Correct | 45 ms | 19912 KB | Output is correct |
38 | Correct | 56 ms | 20272 KB | Output is correct |
39 | Correct | 45 ms | 20048 KB | Output is correct |
40 | Correct | 64 ms | 20060 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6488 KB | Output is correct |
3 | Correct | 2 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6488 KB | Output is correct |
11 | Correct | 211 ms | 21272 KB | Output is correct |
12 | Correct | 205 ms | 20564 KB | Output is correct |
13 | Correct | 234 ms | 19880 KB | Output is correct |
14 | Correct | 233 ms | 20048 KB | Output is correct |
15 | Correct | 218 ms | 21120 KB | Output is correct |
16 | Correct | 249 ms | 20140 KB | Output is correct |
17 | Correct | 295 ms | 20560 KB | Output is correct |
18 | Correct | 172 ms | 22028 KB | Output is correct |
19 | Correct | 196 ms | 18956 KB | Output is correct |
20 | Correct | 212 ms | 20536 KB | Output is correct |
21 | Correct | 228 ms | 23728 KB | Output is correct |
22 | Correct | 237 ms | 23804 KB | Output is correct |
23 | Correct | 277 ms | 23304 KB | Output is correct |
24 | Correct | 265 ms | 22812 KB | Output is correct |
25 | Correct | 253 ms | 24724 KB | Output is correct |
26 | Correct | 273 ms | 23236 KB | Output is correct |
27 | Correct | 324 ms | 23076 KB | Output is correct |
28 | Correct | 187 ms | 25668 KB | Output is correct |
29 | Correct | 227 ms | 21572 KB | Output is correct |
30 | Correct | 237 ms | 23900 KB | Output is correct |
31 | Correct | 260 ms | 23828 KB | Output is correct |
32 | Correct | 265 ms | 23632 KB | Output is correct |
33 | Correct | 243 ms | 22656 KB | Output is correct |
34 | Correct | 264 ms | 22612 KB | Output is correct |
35 | Correct | 269 ms | 23120 KB | Output is correct |
36 | Correct | 183 ms | 21816 KB | Output is correct |
37 | Correct | 220 ms | 23600 KB | Output is correct |
38 | Correct | 238 ms | 21804 KB | Output is correct |
39 | Correct | 256 ms | 22772 KB | Output is correct |
40 | Correct | 265 ms | 22720 KB | Output is correct |
41 | Correct | 40 ms | 20136 KB | Output is correct |
42 | Correct | 39 ms | 20052 KB | Output is correct |
43 | Correct | 45 ms | 20052 KB | Output is correct |
44 | Correct | 55 ms | 20044 KB | Output is correct |
45 | Correct | 43 ms | 19988 KB | Output is correct |
46 | Correct | 50 ms | 20052 KB | Output is correct |
47 | Correct | 49 ms | 20052 KB | Output is correct |
48 | Correct | 32 ms | 20156 KB | Output is correct |
49 | Correct | 54 ms | 19792 KB | Output is correct |
50 | Correct | 49 ms | 19992 KB | Output is correct |
51 | Correct | 58 ms | 19980 KB | Output is correct |
52 | Correct | 51 ms | 20012 KB | Output is correct |
53 | Correct | 46 ms | 20016 KB | Output is correct |
54 | Correct | 51 ms | 20028 KB | Output is correct |
55 | Correct | 55 ms | 20024 KB | Output is correct |
56 | Correct | 32 ms | 19988 KB | Output is correct |
57 | Correct | 42 ms | 20164 KB | Output is correct |
58 | Correct | 40 ms | 19804 KB | Output is correct |
59 | Correct | 44 ms | 20052 KB | Output is correct |
60 | Correct | 56 ms | 20052 KB | Output is correct |
61 | Correct | 38 ms | 19976 KB | Output is correct |
62 | Correct | 54 ms | 20080 KB | Output is correct |
63 | Correct | 49 ms | 20012 KB | Output is correct |
64 | Correct | 31 ms | 19796 KB | Output is correct |
65 | Correct | 45 ms | 19900 KB | Output is correct |
66 | Correct | 45 ms | 20048 KB | Output is correct |
67 | Correct | 45 ms | 19912 KB | Output is correct |
68 | Correct | 56 ms | 20272 KB | Output is correct |
69 | Correct | 45 ms | 20048 KB | Output is correct |
70 | Correct | 64 ms | 20060 KB | Output is correct |
71 | Correct | 322 ms | 43280 KB | Output is correct |
72 | Correct | 308 ms | 43248 KB | Output is correct |
73 | Correct | 458 ms | 41968 KB | Output is correct |
74 | Correct | 545 ms | 42360 KB | Output is correct |
75 | Correct | 318 ms | 44028 KB | Output is correct |
76 | Correct | 729 ms | 42500 KB | Output is correct |
77 | Correct | 623 ms | 42344 KB | Output is correct |
78 | Correct | 274 ms | 46344 KB | Output is correct |
79 | Correct | 304 ms | 40156 KB | Output is correct |
80 | Correct | 350 ms | 43984 KB | Output is correct |
81 | Correct | 512 ms | 44316 KB | Output is correct |
82 | Correct | 536 ms | 43376 KB | Output is correct |
83 | Correct | 352 ms | 42512 KB | Output is correct |
84 | Correct | 665 ms | 43348 KB | Output is correct |
85 | Correct | 677 ms | 43624 KB | Output is correct |
86 | Correct | 260 ms | 41156 KB | Output is correct |
87 | Correct | 334 ms | 44604 KB | Output is correct |
88 | Correct | 323 ms | 41496 KB | Output is correct |
89 | Correct | 395 ms | 43276 KB | Output is correct |
90 | Correct | 435 ms | 43348 KB | Output is correct |
91 | Correct | 385 ms | 42528 KB | Output is correct |
92 | Correct | 706 ms | 43860 KB | Output is correct |
93 | Correct | 676 ms | 43488 KB | Output is correct |
94 | Correct | 206 ms | 41440 KB | Output is correct |
95 | Correct | 496 ms | 42336 KB | Output is correct |
96 | Correct | 502 ms | 42792 KB | Output is correct |
97 | Correct | 518 ms | 42692 KB | Output is correct |
98 | Correct | 514 ms | 42680 KB | Output is correct |
99 | Correct | 483 ms | 42236 KB | Output is correct |
100 | Correct | 565 ms | 42408 KB | Output is correct |