# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
210489 | 2020-03-17T14:09:01 Z | SamAnd | Snake Escaping (JOI18_snake_escaping) | C++17 | 660 ms | 51448 KB |
#include <bits/stdc++.h> using namespace std; const int N = 22, Q = 1000006; int n, qq; char a[(1 << N)]; bool so(const char a[], const char b[]) { for (int i = 1; i <= n; ++i) { if (a[i] != b[i]) return a[i] < b[i]; } return false; } struct ban { int i; char u[N]; }; bool operator<(const ban& a, const ban& b) { return so(a.u, b.u); } ban b[Q]; int* t[N]; int ans[Q]; void rec(int i, int x, int u) { if (i == n + 1) { ans[b[u].i] += t[n][x]; return; } if (b[u].u[i] == '0') rec(i + 1, x, u); else if (b[u].u[i] == '1') rec(i + 1, x, u + (1 << (n - i))); else { rec(i + 1, x, u); rec(i + 1, x, u + (1 << (n - i))); } } int main() { scanf("%d%d", &n, &qq); scanf(" %s", a); for (int i = 0; i < (1 << n); ++i) a[i] -= '0'; for (int i = 0; i < qq; ++i) { b[i].i = i; scanf(" %s", (b[i].u + 1)); } sort(b, b + qq); for (int j = 0; j <= n; ++j) t[j] = new int[(1 << (n - j))]; for (int k = 0; k < (1 << n); ++k) t[0][k] = a[k]; for (int i = 0; i < qq; ++i) { int s = 14; for (int j = 1; j <= min(n, 13); ++j) { if (i == 0 || b[i].u[j] != b[i - 1].u[j]) { s = j; break; } } for (int j = s; j <= min(n, 13); ++j) { if (b[i].u[j] == '0') { for (int k = 0; k < (1 << (n - j)); ++k) { t[j][k] = t[j - 1][k]; } } else if (b[i].u[j] == '1') { for (int k = 0; k < (1 << (n - j)); ++k) { t[j][k] = t[j - 1][k + (1 << (n - j))]; } } else { for (int k = 0; k < (1 << (n - j)); ++k) { t[j][k] = t[j - 1][k] + t[j - 1][k + (1 << (n - j))]; } } } if (n <= 13) { ans[b[i].i] = t[n][0]; continue; } rec(14, 0, i); } for (int i = 0; i < qq; ++i) printf("%d\n", ans[i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 428 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 428 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Correct | 464 ms | 46460 KB | Output is correct |
12 | Correct | 523 ms | 46072 KB | Output is correct |
13 | Correct | 506 ms | 45304 KB | Output is correct |
14 | Correct | 514 ms | 45432 KB | Output is correct |
15 | Correct | 478 ms | 46376 KB | Output is correct |
16 | Correct | 506 ms | 45560 KB | Output is correct |
17 | Correct | 555 ms | 45560 KB | Output is correct |
18 | Correct | 375 ms | 47352 KB | Output is correct |
19 | Correct | 470 ms | 44368 KB | Output is correct |
20 | Correct | 517 ms | 46072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 428 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Correct | 464 ms | 46460 KB | Output is correct |
12 | Correct | 523 ms | 46072 KB | Output is correct |
13 | Correct | 506 ms | 45304 KB | Output is correct |
14 | Correct | 514 ms | 45432 KB | Output is correct |
15 | Correct | 478 ms | 46376 KB | Output is correct |
16 | Correct | 506 ms | 45560 KB | Output is correct |
17 | Correct | 555 ms | 45560 KB | Output is correct |
18 | Correct | 375 ms | 47352 KB | Output is correct |
19 | Correct | 470 ms | 44368 KB | Output is correct |
20 | Correct | 517 ms | 46072 KB | Output is correct |
21 | Correct | 529 ms | 49400 KB | Output is correct |
22 | Correct | 589 ms | 49616 KB | Output is correct |
23 | Correct | 609 ms | 48632 KB | Output is correct |
24 | Correct | 602 ms | 48416 KB | Output is correct |
25 | Correct | 567 ms | 50424 KB | Output is correct |
26 | Correct | 660 ms | 48888 KB | Output is correct |
27 | Correct | 648 ms | 48888 KB | Output is correct |
28 | Correct | 393 ms | 51448 KB | Output is correct |
29 | Correct | 523 ms | 47480 KB | Output is correct |
30 | Correct | 558 ms | 49556 KB | Output is correct |
31 | Correct | 621 ms | 49400 KB | Output is correct |
32 | Correct | 584 ms | 49528 KB | Output is correct |
33 | Correct | 561 ms | 48376 KB | Output is correct |
34 | Correct | 621 ms | 48376 KB | Output is correct |
35 | Correct | 654 ms | 48888 KB | Output is correct |
36 | Correct | 382 ms | 47480 KB | Output is correct |
37 | Correct | 514 ms | 49400 KB | Output is correct |
38 | Correct | 550 ms | 47420 KB | Output is correct |
39 | Correct | 605 ms | 48632 KB | Output is correct |
40 | Correct | 578 ms | 48504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 428 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Incorrect | 83 ms | 13308 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 428 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |
11 | Correct | 464 ms | 46460 KB | Output is correct |
12 | Correct | 523 ms | 46072 KB | Output is correct |
13 | Correct | 506 ms | 45304 KB | Output is correct |
14 | Correct | 514 ms | 45432 KB | Output is correct |
15 | Correct | 478 ms | 46376 KB | Output is correct |
16 | Correct | 506 ms | 45560 KB | Output is correct |
17 | Correct | 555 ms | 45560 KB | Output is correct |
18 | Correct | 375 ms | 47352 KB | Output is correct |
19 | Correct | 470 ms | 44368 KB | Output is correct |
20 | Correct | 517 ms | 46072 KB | Output is correct |
21 | Correct | 529 ms | 49400 KB | Output is correct |
22 | Correct | 589 ms | 49616 KB | Output is correct |
23 | Correct | 609 ms | 48632 KB | Output is correct |
24 | Correct | 602 ms | 48416 KB | Output is correct |
25 | Correct | 567 ms | 50424 KB | Output is correct |
26 | Correct | 660 ms | 48888 KB | Output is correct |
27 | Correct | 648 ms | 48888 KB | Output is correct |
28 | Correct | 393 ms | 51448 KB | Output is correct |
29 | Correct | 523 ms | 47480 KB | Output is correct |
30 | Correct | 558 ms | 49556 KB | Output is correct |
31 | Correct | 621 ms | 49400 KB | Output is correct |
32 | Correct | 584 ms | 49528 KB | Output is correct |
33 | Correct | 561 ms | 48376 KB | Output is correct |
34 | Correct | 621 ms | 48376 KB | Output is correct |
35 | Correct | 654 ms | 48888 KB | Output is correct |
36 | Correct | 382 ms | 47480 KB | Output is correct |
37 | Correct | 514 ms | 49400 KB | Output is correct |
38 | Correct | 550 ms | 47420 KB | Output is correct |
39 | Correct | 605 ms | 48632 KB | Output is correct |
40 | Correct | 578 ms | 48504 KB | Output is correct |
41 | Incorrect | 83 ms | 13308 KB | Output isn't correct |
42 | Halted | 0 ms | 0 KB | - |