# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171468 | 2019-12-28T17:24:46 Z | Akashi | Snake Escaping (JOI18_snake_escaping) | C++14 | 2000 ms | 38520 KB |
#include <bits/stdc++.h> using namespace std; int n, q, L1, L2; int dp[1594330]; int m1[1000005], m2[1000005], ans[1000005]; int p3[25], p2[25]; char s[1048580]; char in[25]; bool f[2200][130]; int main() { scanf("%d%d", &n, &q); scanf("%s", s); p3[0] = 1; for(int i = 1; i <= 21 ; ++i) p3[i] = p3[i - 1] * 3; p2[0] = 1; for(int i = 1; i <= 21 ; ++i) p2[i] = p2[i - 1] * 2; if(n >= 10) L1 = 7, L2 = n - L1; else L1 = 1, L2 = n - L1; for(int mask = 0; mask < p3[L1] ; ++mask){ for(int mask2 = 0; mask2 < p2[L1] ; ++mask2){ bool ok = true; for(int i = 0; i < L1 ; ++i){ int x = (mask % p3[i + 1]) / p3[i]; int y = (mask2 & p2[i]) > 0; if(x == y || x == 2) continue ; ok = false; break ; } f[mask][mask2] = ok; } } for(int i = 1; i <= q ; ++i){ scanf("%s", in); for(int j = 0; j < L1 ; ++j){ int x; if(in[j] == '0') x = 0; else if(in[j] == '1') x = 1; else x = 2; m1[i] = m1[i] + x * p3[L1 - j - 1]; } for(int j = L1; j < n ; ++j){ int x; if(in[j] == '0') x = 0; else if(in[j] == '1') x = 1; else x = 2; m2[i] = m2[i] + x * p3[j - L1]; } } int P = (1 << L1); for(int mask2 = 0; mask2 < P ; ++mask2){ memset(dp, 0, sizeof(dp)); int ad = mask2 * p2[L2]; for(int mask = 0; mask < p3[L2] ; ++mask){ bool found = false; int mask2 = 0; for(int i = 0; i < L2 ; ++i){ int x = (mask % p3[i + 1]) / p3[i]; if(x == 2){ found = true; dp[mask] = dp[mask - x * p3[i]] + dp[mask - x * p3[i] + p3[i]]; break ; } else mask2 = mask2 + x * p2[L2 - i - 1]; } if(!found) dp[mask] = s[mask2 + ad] - '0'; } for(int i = 1; i <= q ; ++i){ if(f[m1[i]][mask2]) ans[i] += dp[m2[i]]; } } for(int i = 1; i <= q ; ++i) printf("%d\n", ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 6904 KB | Output is correct |
2 | Correct | 56 ms | 6904 KB | Output is correct |
3 | Correct | 57 ms | 6964 KB | Output is correct |
4 | Correct | 57 ms | 7036 KB | Output is correct |
5 | Correct | 58 ms | 7000 KB | Output is correct |
6 | Correct | 59 ms | 6904 KB | Output is correct |
7 | Correct | 56 ms | 6904 KB | Output is correct |
8 | Correct | 57 ms | 6904 KB | Output is correct |
9 | Correct | 56 ms | 6904 KB | Output is correct |
10 | Correct | 59 ms | 6904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 6904 KB | Output is correct |
2 | Correct | 56 ms | 6904 KB | Output is correct |
3 | Correct | 57 ms | 6964 KB | Output is correct |
4 | Correct | 57 ms | 7036 KB | Output is correct |
5 | Correct | 58 ms | 7000 KB | Output is correct |
6 | Correct | 59 ms | 6904 KB | Output is correct |
7 | Correct | 56 ms | 6904 KB | Output is correct |
8 | Correct | 57 ms | 6904 KB | Output is correct |
9 | Correct | 56 ms | 6904 KB | Output is correct |
10 | Correct | 59 ms | 6904 KB | Output is correct |
11 | Correct | 680 ms | 33492 KB | Output is correct |
12 | Correct | 899 ms | 33016 KB | Output is correct |
13 | Correct | 672 ms | 32376 KB | Output is correct |
14 | Correct | 663 ms | 32376 KB | Output is correct |
15 | Correct | 900 ms | 33400 KB | Output is correct |
16 | Correct | 711 ms | 32604 KB | Output is correct |
17 | Correct | 839 ms | 32560 KB | Output is correct |
18 | Correct | 491 ms | 34488 KB | Output is correct |
19 | Correct | 605 ms | 31420 KB | Output is correct |
20 | Correct | 801 ms | 33056 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 6904 KB | Output is correct |
2 | Correct | 56 ms | 6904 KB | Output is correct |
3 | Correct | 57 ms | 6964 KB | Output is correct |
4 | Correct | 57 ms | 7036 KB | Output is correct |
5 | Correct | 58 ms | 7000 KB | Output is correct |
6 | Correct | 59 ms | 6904 KB | Output is correct |
7 | Correct | 56 ms | 6904 KB | Output is correct |
8 | Correct | 57 ms | 6904 KB | Output is correct |
9 | Correct | 56 ms | 6904 KB | Output is correct |
10 | Correct | 59 ms | 6904 KB | Output is correct |
11 | Correct | 680 ms | 33492 KB | Output is correct |
12 | Correct | 899 ms | 33016 KB | Output is correct |
13 | Correct | 672 ms | 32376 KB | Output is correct |
14 | Correct | 663 ms | 32376 KB | Output is correct |
15 | Correct | 900 ms | 33400 KB | Output is correct |
16 | Correct | 711 ms | 32604 KB | Output is correct |
17 | Correct | 839 ms | 32560 KB | Output is correct |
18 | Correct | 491 ms | 34488 KB | Output is correct |
19 | Correct | 605 ms | 31420 KB | Output is correct |
20 | Correct | 801 ms | 33056 KB | Output is correct |
21 | Correct | 764 ms | 36328 KB | Output is correct |
22 | Correct | 847 ms | 36456 KB | Output is correct |
23 | Correct | 852 ms | 35688 KB | Output is correct |
24 | Correct | 837 ms | 35448 KB | Output is correct |
25 | Correct | 997 ms | 37348 KB | Output is correct |
26 | Correct | 902 ms | 35932 KB | Output is correct |
27 | Correct | 898 ms | 35832 KB | Output is correct |
28 | Correct | 525 ms | 38520 KB | Output is correct |
29 | Correct | 604 ms | 34480 KB | Output is correct |
30 | Correct | 790 ms | 36600 KB | Output is correct |
31 | Correct | 911 ms | 36436 KB | Output is correct |
32 | Correct | 885 ms | 36580 KB | Output is correct |
33 | Correct | 621 ms | 35160 KB | Output is correct |
34 | Correct | 927 ms | 35580 KB | Output is correct |
35 | Correct | 966 ms | 35968 KB | Output is correct |
36 | Correct | 437 ms | 34304 KB | Output is correct |
37 | Correct | 772 ms | 36296 KB | Output is correct |
38 | Correct | 587 ms | 34464 KB | Output is correct |
39 | Correct | 873 ms | 35584 KB | Output is correct |
40 | Correct | 816 ms | 35412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 6904 KB | Output is correct |
2 | Correct | 56 ms | 6904 KB | Output is correct |
3 | Correct | 57 ms | 6964 KB | Output is correct |
4 | Correct | 57 ms | 7036 KB | Output is correct |
5 | Correct | 58 ms | 7000 KB | Output is correct |
6 | Correct | 59 ms | 6904 KB | Output is correct |
7 | Correct | 56 ms | 6904 KB | Output is correct |
8 | Correct | 57 ms | 6904 KB | Output is correct |
9 | Correct | 56 ms | 6904 KB | Output is correct |
10 | Correct | 59 ms | 6904 KB | Output is correct |
11 | Execution timed out | 2027 ms | 10488 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 6904 KB | Output is correct |
2 | Correct | 56 ms | 6904 KB | Output is correct |
3 | Correct | 57 ms | 6964 KB | Output is correct |
4 | Correct | 57 ms | 7036 KB | Output is correct |
5 | Correct | 58 ms | 7000 KB | Output is correct |
6 | Correct | 59 ms | 6904 KB | Output is correct |
7 | Correct | 56 ms | 6904 KB | Output is correct |
8 | Correct | 57 ms | 6904 KB | Output is correct |
9 | Correct | 56 ms | 6904 KB | Output is correct |
10 | Correct | 59 ms | 6904 KB | Output is correct |
11 | Correct | 680 ms | 33492 KB | Output is correct |
12 | Correct | 899 ms | 33016 KB | Output is correct |
13 | Correct | 672 ms | 32376 KB | Output is correct |
14 | Correct | 663 ms | 32376 KB | Output is correct |
15 | Correct | 900 ms | 33400 KB | Output is correct |
16 | Correct | 711 ms | 32604 KB | Output is correct |
17 | Correct | 839 ms | 32560 KB | Output is correct |
18 | Correct | 491 ms | 34488 KB | Output is correct |
19 | Correct | 605 ms | 31420 KB | Output is correct |
20 | Correct | 801 ms | 33056 KB | Output is correct |
21 | Correct | 764 ms | 36328 KB | Output is correct |
22 | Correct | 847 ms | 36456 KB | Output is correct |
23 | Correct | 852 ms | 35688 KB | Output is correct |
24 | Correct | 837 ms | 35448 KB | Output is correct |
25 | Correct | 997 ms | 37348 KB | Output is correct |
26 | Correct | 902 ms | 35932 KB | Output is correct |
27 | Correct | 898 ms | 35832 KB | Output is correct |
28 | Correct | 525 ms | 38520 KB | Output is correct |
29 | Correct | 604 ms | 34480 KB | Output is correct |
30 | Correct | 790 ms | 36600 KB | Output is correct |
31 | Correct | 911 ms | 36436 KB | Output is correct |
32 | Correct | 885 ms | 36580 KB | Output is correct |
33 | Correct | 621 ms | 35160 KB | Output is correct |
34 | Correct | 927 ms | 35580 KB | Output is correct |
35 | Correct | 966 ms | 35968 KB | Output is correct |
36 | Correct | 437 ms | 34304 KB | Output is correct |
37 | Correct | 772 ms | 36296 KB | Output is correct |
38 | Correct | 587 ms | 34464 KB | Output is correct |
39 | Correct | 873 ms | 35584 KB | Output is correct |
40 | Correct | 816 ms | 35412 KB | Output is correct |
41 | Execution timed out | 2027 ms | 10488 KB | Time limit exceeded |
42 | Halted | 0 ms | 0 KB | - |