# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
204075 | 2020-02-24T08:37:22 Z | Kastanda | Snake Escaping (JOI18_snake_escaping) | C++11 | 1450 ms | 51696 KB |
// In The Name Of The Queen #include<bits/stdc++.h> using namespace std; const int N = 20, K = 12, M = 8, MXK = 531441, MXM = 6561, MAXQ = 1e6 + 9; // MXK = 3 ^ K, MXM = 3 ^ M int n, q, k, m, RS[MAXQ], Val[MAXQ]; int L[MXK], R[MXK], B[MXK], dp[MXK]; char A[1 << N], Tmp[N]; vector < int > Q[MXM]; int main() { scanf("%d%d%s", &n, &q, A); for (int i = 0; i < (1 << n); i ++) A[i] -= '0'; k = min(K, n); m = n - k; for (int i = 0; i < q; i ++) { scanf("%s", Tmp); for (int j = 0; j < n; j ++) { if (Tmp[j] == '?') Tmp[j] = '2'; Tmp[j] -= '0'; } int pref = 0; for (int j = 0; j < m; j ++) pref = (pref << 1) + pref + Tmp[j]; int suff = 0; for (int j = m; j < n; j ++) suff = (suff << 1) + suff + Tmp[j]; Val[i] = suff; Q[pref].push_back(i); } int k3 = 1; for (int i = 0; i < k; i ++) k3 *= 3; for (int state = 0; state < k3; state ++) { int tmp = state; for (int j = 0; j < k; j ++) Tmp[j] = tmp % 3, tmp /= 3; int h = -1; for (int j = 0; j < k; j ++) if (Tmp[j] == 2) h = j; if (h == -1) { for (int j = 0; j < k; j ++) B[state] |= Tmp[j] << j; continue; } B[state] = -1; Tmp[h] = 0; for (int j = k - 1; ~ j; j --) L[state] = L[state] * 3 + Tmp[j]; Tmp[h] = 1; for (int j = k - 1; ~ j; j --) R[state] = R[state] * 3 + Tmp[j]; } for (int mask = 0; mask < (1 << m); mask ++) { for (int state = 0; state < k3; state ++) { if (B[state] != -1) dp[state] = A[(mask << k) | B[state]]; else dp[state] = dp[L[state]] + dp[R[state]]; } for (int sk = 0; sk < (1 << m); sk ++) { for (int j = 0; j < m; j ++) { if (sk >> j & 1) Tmp[j] = 2; else Tmp[j] = mask >> j & 1; } int pref = 0; for (int j = m - 1; ~ j; j --) pref = pref * 3 + Tmp[j]; for (int i : Q[pref]) RS[i] += dp[Val[i]]; } } for (int i = 0; i < q; i ++) printf("%d\n", RS[i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1528 KB | Output is correct |
7 | Correct | 8 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 8 ms | 1400 KB | Output is correct |
10 | Correct | 9 ms | 1448 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1528 KB | Output is correct |
7 | Correct | 8 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 8 ms | 1400 KB | Output is correct |
10 | Correct | 9 ms | 1448 KB | Output is correct |
11 | Correct | 279 ms | 28044 KB | Output is correct |
12 | Correct | 274 ms | 27740 KB | Output is correct |
13 | Correct | 258 ms | 26928 KB | Output is correct |
14 | Correct | 255 ms | 27100 KB | Output is correct |
15 | Correct | 254 ms | 28124 KB | Output is correct |
16 | Correct | 258 ms | 27228 KB | Output is correct |
17 | Correct | 253 ms | 27228 KB | Output is correct |
18 | Correct | 246 ms | 29148 KB | Output is correct |
19 | Correct | 245 ms | 26204 KB | Output is correct |
20 | Correct | 255 ms | 27740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1528 KB | Output is correct |
7 | Correct | 8 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 8 ms | 1400 KB | Output is correct |
10 | Correct | 9 ms | 1448 KB | Output is correct |
11 | Correct | 279 ms | 28044 KB | Output is correct |
12 | Correct | 274 ms | 27740 KB | Output is correct |
13 | Correct | 258 ms | 26928 KB | Output is correct |
14 | Correct | 255 ms | 27100 KB | Output is correct |
15 | Correct | 254 ms | 28124 KB | Output is correct |
16 | Correct | 258 ms | 27228 KB | Output is correct |
17 | Correct | 253 ms | 27228 KB | Output is correct |
18 | Correct | 246 ms | 29148 KB | Output is correct |
19 | Correct | 245 ms | 26204 KB | Output is correct |
20 | Correct | 255 ms | 27740 KB | Output is correct |
21 | Correct | 292 ms | 38480 KB | Output is correct |
22 | Correct | 307 ms | 38560 KB | Output is correct |
23 | Correct | 306 ms | 37776 KB | Output is correct |
24 | Correct | 299 ms | 37452 KB | Output is correct |
25 | Correct | 301 ms | 40808 KB | Output is correct |
26 | Correct | 303 ms | 38088 KB | Output is correct |
27 | Correct | 313 ms | 38140 KB | Output is correct |
28 | Correct | 300 ms | 40540 KB | Output is correct |
29 | Correct | 288 ms | 36556 KB | Output is correct |
30 | Correct | 309 ms | 38524 KB | Output is correct |
31 | Correct | 292 ms | 38496 KB | Output is correct |
32 | Correct | 296 ms | 38348 KB | Output is correct |
33 | Correct | 291 ms | 38056 KB | Output is correct |
34 | Correct | 291 ms | 37412 KB | Output is correct |
35 | Correct | 302 ms | 38156 KB | Output is correct |
36 | Correct | 288 ms | 36368 KB | Output is correct |
37 | Correct | 298 ms | 38476 KB | Output is correct |
38 | Correct | 281 ms | 36356 KB | Output is correct |
39 | Correct | 301 ms | 37708 KB | Output is correct |
40 | Correct | 301 ms | 37576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1528 KB | Output is correct |
7 | Correct | 8 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 8 ms | 1400 KB | Output is correct |
10 | Correct | 9 ms | 1448 KB | Output is correct |
11 | Correct | 251 ms | 12880 KB | Output is correct |
12 | Correct | 253 ms | 12792 KB | Output is correct |
13 | Correct | 264 ms | 12904 KB | Output is correct |
14 | Correct | 266 ms | 12920 KB | Output is correct |
15 | Correct | 272 ms | 13048 KB | Output is correct |
16 | Correct | 258 ms | 12920 KB | Output is correct |
17 | Correct | 268 ms | 12920 KB | Output is correct |
18 | Correct | 304 ms | 13068 KB | Output is correct |
19 | Correct | 243 ms | 12664 KB | Output is correct |
20 | Correct | 257 ms | 13048 KB | Output is correct |
21 | Correct | 258 ms | 12920 KB | Output is correct |
22 | Correct | 264 ms | 12920 KB | Output is correct |
23 | Correct | 247 ms | 12792 KB | Output is correct |
24 | Correct | 249 ms | 12896 KB | Output is correct |
25 | Correct | 263 ms | 13048 KB | Output is correct |
26 | Correct | 241 ms | 12788 KB | Output is correct |
27 | Correct | 246 ms | 12920 KB | Output is correct |
28 | Correct | 246 ms | 12664 KB | Output is correct |
29 | Correct | 251 ms | 12920 KB | Output is correct |
30 | Correct | 258 ms | 12920 KB | Output is correct |
31 | Correct | 248 ms | 12792 KB | Output is correct |
32 | Correct | 274 ms | 12920 KB | Output is correct |
33 | Correct | 258 ms | 12920 KB | Output is correct |
34 | Correct | 243 ms | 12660 KB | Output is correct |
35 | Correct | 266 ms | 12920 KB | Output is correct |
36 | Correct | 262 ms | 12920 KB | Output is correct |
37 | Correct | 268 ms | 13048 KB | Output is correct |
38 | Correct | 262 ms | 12920 KB | Output is correct |
39 | Correct | 263 ms | 12924 KB | Output is correct |
40 | Correct | 261 ms | 12920 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1400 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 8 ms | 1400 KB | Output is correct |
4 | Correct | 8 ms | 1400 KB | Output is correct |
5 | Correct | 8 ms | 1528 KB | Output is correct |
6 | Correct | 8 ms | 1528 KB | Output is correct |
7 | Correct | 8 ms | 1528 KB | Output is correct |
8 | Correct | 8 ms | 1528 KB | Output is correct |
9 | Correct | 8 ms | 1400 KB | Output is correct |
10 | Correct | 9 ms | 1448 KB | Output is correct |
11 | Correct | 279 ms | 28044 KB | Output is correct |
12 | Correct | 274 ms | 27740 KB | Output is correct |
13 | Correct | 258 ms | 26928 KB | Output is correct |
14 | Correct | 255 ms | 27100 KB | Output is correct |
15 | Correct | 254 ms | 28124 KB | Output is correct |
16 | Correct | 258 ms | 27228 KB | Output is correct |
17 | Correct | 253 ms | 27228 KB | Output is correct |
18 | Correct | 246 ms | 29148 KB | Output is correct |
19 | Correct | 245 ms | 26204 KB | Output is correct |
20 | Correct | 255 ms | 27740 KB | Output is correct |
21 | Correct | 292 ms | 38480 KB | Output is correct |
22 | Correct | 307 ms | 38560 KB | Output is correct |
23 | Correct | 306 ms | 37776 KB | Output is correct |
24 | Correct | 299 ms | 37452 KB | Output is correct |
25 | Correct | 301 ms | 40808 KB | Output is correct |
26 | Correct | 303 ms | 38088 KB | Output is correct |
27 | Correct | 313 ms | 38140 KB | Output is correct |
28 | Correct | 300 ms | 40540 KB | Output is correct |
29 | Correct | 288 ms | 36556 KB | Output is correct |
30 | Correct | 309 ms | 38524 KB | Output is correct |
31 | Correct | 292 ms | 38496 KB | Output is correct |
32 | Correct | 296 ms | 38348 KB | Output is correct |
33 | Correct | 291 ms | 38056 KB | Output is correct |
34 | Correct | 291 ms | 37412 KB | Output is correct |
35 | Correct | 302 ms | 38156 KB | Output is correct |
36 | Correct | 288 ms | 36368 KB | Output is correct |
37 | Correct | 298 ms | 38476 KB | Output is correct |
38 | Correct | 281 ms | 36356 KB | Output is correct |
39 | Correct | 301 ms | 37708 KB | Output is correct |
40 | Correct | 301 ms | 37576 KB | Output is correct |
41 | Correct | 251 ms | 12880 KB | Output is correct |
42 | Correct | 253 ms | 12792 KB | Output is correct |
43 | Correct | 264 ms | 12904 KB | Output is correct |
44 | Correct | 266 ms | 12920 KB | Output is correct |
45 | Correct | 272 ms | 13048 KB | Output is correct |
46 | Correct | 258 ms | 12920 KB | Output is correct |
47 | Correct | 268 ms | 12920 KB | Output is correct |
48 | Correct | 304 ms | 13068 KB | Output is correct |
49 | Correct | 243 ms | 12664 KB | Output is correct |
50 | Correct | 257 ms | 13048 KB | Output is correct |
51 | Correct | 258 ms | 12920 KB | Output is correct |
52 | Correct | 264 ms | 12920 KB | Output is correct |
53 | Correct | 247 ms | 12792 KB | Output is correct |
54 | Correct | 249 ms | 12896 KB | Output is correct |
55 | Correct | 263 ms | 13048 KB | Output is correct |
56 | Correct | 241 ms | 12788 KB | Output is correct |
57 | Correct | 246 ms | 12920 KB | Output is correct |
58 | Correct | 246 ms | 12664 KB | Output is correct |
59 | Correct | 251 ms | 12920 KB | Output is correct |
60 | Correct | 258 ms | 12920 KB | Output is correct |
61 | Correct | 248 ms | 12792 KB | Output is correct |
62 | Correct | 274 ms | 12920 KB | Output is correct |
63 | Correct | 258 ms | 12920 KB | Output is correct |
64 | Correct | 243 ms | 12660 KB | Output is correct |
65 | Correct | 266 ms | 12920 KB | Output is correct |
66 | Correct | 262 ms | 12920 KB | Output is correct |
67 | Correct | 268 ms | 13048 KB | Output is correct |
68 | Correct | 262 ms | 12920 KB | Output is correct |
69 | Correct | 263 ms | 12924 KB | Output is correct |
70 | Correct | 261 ms | 12920 KB | Output is correct |
71 | Correct | 814 ms | 51312 KB | Output is correct |
72 | Correct | 857 ms | 49012 KB | Output is correct |
73 | Correct | 712 ms | 50168 KB | Output is correct |
74 | Correct | 790 ms | 49136 KB | Output is correct |
75 | Correct | 1308 ms | 51188 KB | Output is correct |
76 | Correct | 852 ms | 49688 KB | Output is correct |
77 | Correct | 885 ms | 50740 KB | Output is correct |
78 | Correct | 1450 ms | 51276 KB | Output is correct |
79 | Correct | 554 ms | 47600 KB | Output is correct |
80 | Correct | 855 ms | 48960 KB | Output is correct |
81 | Correct | 1010 ms | 51696 KB | Output is correct |
82 | Correct | 803 ms | 49136 KB | Output is correct |
83 | Correct | 637 ms | 48244 KB | Output is correct |
84 | Correct | 779 ms | 49392 KB | Output is correct |
85 | Correct | 806 ms | 50800 KB | Output is correct |
86 | Correct | 523 ms | 45524 KB | Output is correct |
87 | Correct | 794 ms | 50692 KB | Output is correct |
88 | Correct | 553 ms | 45808 KB | Output is correct |
89 | Correct | 720 ms | 50280 KB | Output is correct |
90 | Correct | 744 ms | 48980 KB | Output is correct |
91 | Correct | 624 ms | 48240 KB | Output is correct |
92 | Correct | 848 ms | 49664 KB | Output is correct |
93 | Correct | 870 ms | 50888 KB | Output is correct |
94 | Correct | 524 ms | 45268 KB | Output is correct |
95 | Correct | 1004 ms | 48992 KB | Output is correct |
96 | Correct | 1008 ms | 49208 KB | Output is correct |
97 | Correct | 1012 ms | 49076 KB | Output is correct |
98 | Correct | 1002 ms | 49156 KB | Output is correct |
99 | Correct | 998 ms | 49072 KB | Output is correct |
100 | Correct | 989 ms | 48964 KB | Output is correct |