# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
135183 | 2019-07-23T18:55:27 Z | duality | Snake Escaping (JOI18_snake_escaping) | C++11 | 2000 ms | 39868 KB |
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; int H = 9; char S[(1 << 20)+1],T[21]; struct query { int m1,m2,i; }; query queries[1000000]; int pow3[21]; int ans[1000000]; int num[1594323]; int sum[1594323]; int main() { int i,j; int L,Q; scanf("%d %d %s",&L,&Q,S); H = min(H,L); for (i = 0; i < Q; i++) { scanf("%s",T),queries[i].i = i; reverse(T,T+H),reverse(T+H,T+L); for (j = 0; j < H; j++) { if (T[j] == '0') queries[i].m1 |= (1 << (2*j)); else if (T[j] == '1') queries[i].m1 |= (1 << (2*j+1)); else queries[i].m1 |= (1 << (2*j)) | (1 << (2*j+1)); } int p = 1; for (j = H; j < L; j++) { if (T[j] == '1') queries[i].m2 += p; else if (T[j] == '?') queries[i].m2 += 2*p; p *= 3; } } int k; pow3[0] = 1; for (i = 1; i <= L; i++) pow3[i] = pow3[i-1]*3; for (i = 0; i < pow3[L-H]; i++) { int n = i; for (j = 0; j < L-H; j++) { if ((n % 3) == 0) num[i] |= (1 << (2*j)); else if ((n % 3) == 1) num[i] |= (1 << (2*j+1)); else num[i] |= (1 << (2*j)) | (1 << (2*j+1)); n /= 3; } } for (i = 0; i < (1 << H); i++) { for (j = 0; j < (1 << (L-H)); j++) { int c = 0; for (k = 0; k < L-H; k++) { if (j & (1 << k)) c += pow3[k]; } sum[c] = S[j+i*(1 << (L-H))]-'0'; } for (j = 0; j < L-H; j++) { for (k = 0; k < pow3[L-H]; k++) { if (((num[k] >> (2*j)) & 3) == 3) sum[k] = sum[k-pow3[j]]+sum[k-2*pow3[j]]; } } int m = 0; for (j = 0; j < H; j++) { if (i & (1 << j)) m |= (1 << (2*j+1)); else m |= (1 << (2*j)); } for (j = 0; j < Q; j++) { if ((queries[j].m1 & m) == m) ans[queries[j].i] += sum[queries[j].m2]; } } for (i = 0; i < Q; i++) printf("%d\n",ans[i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 408 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 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 | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 408 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 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 | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 1239 ms | 22664 KB | Output is correct |
12 | Correct | 1354 ms | 22208 KB | Output is correct |
13 | Correct | 1190 ms | 21304 KB | Output is correct |
14 | Correct | 1244 ms | 21436 KB | Output is correct |
15 | Correct | 1485 ms | 22500 KB | Output is correct |
16 | Correct | 1100 ms | 21572 KB | Output is correct |
17 | Correct | 1061 ms | 21604 KB | Output is correct |
18 | Correct | 1901 ms | 23472 KB | Output is correct |
19 | Correct | 911 ms | 20500 KB | Output is correct |
20 | Correct | 1430 ms | 22060 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 408 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 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 | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 1239 ms | 22664 KB | Output is correct |
12 | Correct | 1354 ms | 22208 KB | Output is correct |
13 | Correct | 1190 ms | 21304 KB | Output is correct |
14 | Correct | 1244 ms | 21436 KB | Output is correct |
15 | Correct | 1485 ms | 22500 KB | Output is correct |
16 | Correct | 1100 ms | 21572 KB | Output is correct |
17 | Correct | 1061 ms | 21604 KB | Output is correct |
18 | Correct | 1901 ms | 23472 KB | Output is correct |
19 | Correct | 911 ms | 20500 KB | Output is correct |
20 | Correct | 1430 ms | 22060 KB | Output is correct |
21 | Correct | 1386 ms | 22328 KB | Output is correct |
22 | Correct | 1467 ms | 22372 KB | Output is correct |
23 | Correct | 1214 ms | 21304 KB | Output is correct |
24 | Correct | 1081 ms | 21084 KB | Output is correct |
25 | Correct | 1645 ms | 23092 KB | Output is correct |
26 | Correct | 1121 ms | 21448 KB | Output is correct |
27 | Correct | 1085 ms | 21308 KB | Output is correct |
28 | Correct | 1935 ms | 23644 KB | Output is correct |
29 | Correct | 955 ms | 19616 KB | Output is correct |
30 | Correct | 1598 ms | 21696 KB | Output is correct |
31 | Correct | 1177 ms | 21572 KB | Output is correct |
32 | Correct | 1347 ms | 21368 KB | Output is correct |
33 | Correct | 1048 ms | 20036 KB | Output is correct |
34 | Correct | 1038 ms | 20216 KB | Output is correct |
35 | Correct | 1118 ms | 20632 KB | Output is correct |
36 | Correct | 728 ms | 19064 KB | Output is correct |
37 | Correct | 1147 ms | 20928 KB | Output is correct |
38 | Correct | 956 ms | 18880 KB | Output is correct |
39 | Correct | 1010 ms | 19908 KB | Output is correct |
40 | Correct | 1062 ms | 19408 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 408 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 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 | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 1623 ms | 4232 KB | Output is correct |
12 | Correct | 1652 ms | 6020 KB | Output is correct |
13 | Correct | 1623 ms | 5800 KB | Output is correct |
14 | Correct | 1636 ms | 5776 KB | Output is correct |
15 | Correct | 1661 ms | 5872 KB | Output is correct |
16 | Correct | 1630 ms | 5880 KB | Output is correct |
17 | Correct | 1646 ms | 5788 KB | Output is correct |
18 | Correct | 1663 ms | 6136 KB | Output is correct |
19 | Correct | 1601 ms | 5724 KB | Output is correct |
20 | Correct | 1627 ms | 5904 KB | Output is correct |
21 | Correct | 1657 ms | 6012 KB | Output is correct |
22 | Correct | 1662 ms | 5784 KB | Output is correct |
23 | Correct | 1628 ms | 5772 KB | Output is correct |
24 | Correct | 1628 ms | 5880 KB | Output is correct |
25 | Correct | 1676 ms | 5824 KB | Output is correct |
26 | Correct | 1594 ms | 5808 KB | Output is correct |
27 | Correct | 1627 ms | 5896 KB | Output is correct |
28 | Correct | 1616 ms | 5624 KB | Output is correct |
29 | Correct | 1651 ms | 5812 KB | Output is correct |
30 | Correct | 1617 ms | 5772 KB | Output is correct |
31 | Correct | 1683 ms | 5776 KB | Output is correct |
32 | Correct | 1641 ms | 5768 KB | Output is correct |
33 | Correct | 1629 ms | 5852 KB | Output is correct |
34 | Correct | 1604 ms | 5752 KB | Output is correct |
35 | Correct | 1678 ms | 5768 KB | Output is correct |
36 | Correct | 1654 ms | 5780 KB | Output is correct |
37 | Correct | 1666 ms | 5772 KB | Output is correct |
38 | Correct | 1643 ms | 5768 KB | Output is correct |
39 | Correct | 1660 ms | 5752 KB | Output is correct |
40 | Correct | 1657 ms | 5756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 408 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 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 | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 1239 ms | 22664 KB | Output is correct |
12 | Correct | 1354 ms | 22208 KB | Output is correct |
13 | Correct | 1190 ms | 21304 KB | Output is correct |
14 | Correct | 1244 ms | 21436 KB | Output is correct |
15 | Correct | 1485 ms | 22500 KB | Output is correct |
16 | Correct | 1100 ms | 21572 KB | Output is correct |
17 | Correct | 1061 ms | 21604 KB | Output is correct |
18 | Correct | 1901 ms | 23472 KB | Output is correct |
19 | Correct | 911 ms | 20500 KB | Output is correct |
20 | Correct | 1430 ms | 22060 KB | Output is correct |
21 | Correct | 1386 ms | 22328 KB | Output is correct |
22 | Correct | 1467 ms | 22372 KB | Output is correct |
23 | Correct | 1214 ms | 21304 KB | Output is correct |
24 | Correct | 1081 ms | 21084 KB | Output is correct |
25 | Correct | 1645 ms | 23092 KB | Output is correct |
26 | Correct | 1121 ms | 21448 KB | Output is correct |
27 | Correct | 1085 ms | 21308 KB | Output is correct |
28 | Correct | 1935 ms | 23644 KB | Output is correct |
29 | Correct | 955 ms | 19616 KB | Output is correct |
30 | Correct | 1598 ms | 21696 KB | Output is correct |
31 | Correct | 1177 ms | 21572 KB | Output is correct |
32 | Correct | 1347 ms | 21368 KB | Output is correct |
33 | Correct | 1048 ms | 20036 KB | Output is correct |
34 | Correct | 1038 ms | 20216 KB | Output is correct |
35 | Correct | 1118 ms | 20632 KB | Output is correct |
36 | Correct | 728 ms | 19064 KB | Output is correct |
37 | Correct | 1147 ms | 20928 KB | Output is correct |
38 | Correct | 956 ms | 18880 KB | Output is correct |
39 | Correct | 1010 ms | 19908 KB | Output is correct |
40 | Correct | 1062 ms | 19408 KB | Output is correct |
41 | Correct | 1623 ms | 4232 KB | Output is correct |
42 | Correct | 1652 ms | 6020 KB | Output is correct |
43 | Correct | 1623 ms | 5800 KB | Output is correct |
44 | Correct | 1636 ms | 5776 KB | Output is correct |
45 | Correct | 1661 ms | 5872 KB | Output is correct |
46 | Correct | 1630 ms | 5880 KB | Output is correct |
47 | Correct | 1646 ms | 5788 KB | Output is correct |
48 | Correct | 1663 ms | 6136 KB | Output is correct |
49 | Correct | 1601 ms | 5724 KB | Output is correct |
50 | Correct | 1627 ms | 5904 KB | Output is correct |
51 | Correct | 1657 ms | 6012 KB | Output is correct |
52 | Correct | 1662 ms | 5784 KB | Output is correct |
53 | Correct | 1628 ms | 5772 KB | Output is correct |
54 | Correct | 1628 ms | 5880 KB | Output is correct |
55 | Correct | 1676 ms | 5824 KB | Output is correct |
56 | Correct | 1594 ms | 5808 KB | Output is correct |
57 | Correct | 1627 ms | 5896 KB | Output is correct |
58 | Correct | 1616 ms | 5624 KB | Output is correct |
59 | Correct | 1651 ms | 5812 KB | Output is correct |
60 | Correct | 1617 ms | 5772 KB | Output is correct |
61 | Correct | 1683 ms | 5776 KB | Output is correct |
62 | Correct | 1641 ms | 5768 KB | Output is correct |
63 | Correct | 1629 ms | 5852 KB | Output is correct |
64 | Correct | 1604 ms | 5752 KB | Output is correct |
65 | Correct | 1678 ms | 5768 KB | Output is correct |
66 | Correct | 1654 ms | 5780 KB | Output is correct |
67 | Correct | 1666 ms | 5772 KB | Output is correct |
68 | Correct | 1643 ms | 5768 KB | Output is correct |
69 | Correct | 1660 ms | 5752 KB | Output is correct |
70 | Correct | 1657 ms | 5756 KB | Output is correct |
71 | Execution timed out | 2033 ms | 39868 KB | Time limit exceeded |
72 | Halted | 0 ms | 0 KB | - |