# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
135186 | 2019-07-23T19:04:05 Z | duality | Snake Escaping (JOI18_snake_escaping) | C++11 | 2000 ms | 20316 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 = 10; char S[(1 << 20)+1],T[21]; struct query { int m1,m2,i; }; query queries[1000000]; int pow3[21]; int ans[1000000]; vi v[20]; 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) == 2) v[j].pb(i); 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 < v[j].size(); k++) sum[v[j][k]] = sum[v[j][k]-pow3[j]]+sum[v[j][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 | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 1795 ms | 20316 KB | Output is correct |
12 | Execution timed out | 2060 ms | 16248 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 1795 ms | 20316 KB | Output is correct |
12 | Execution timed out | 2060 ms | 16248 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 702 ms | 4124 KB | Output is correct |
12 | Correct | 710 ms | 4180 KB | Output is correct |
13 | Correct | 680 ms | 4052 KB | Output is correct |
14 | Correct | 688 ms | 4052 KB | Output is correct |
15 | Correct | 749 ms | 4076 KB | Output is correct |
16 | Correct | 688 ms | 4052 KB | Output is correct |
17 | Correct | 688 ms | 4056 KB | Output is correct |
18 | Correct | 778 ms | 4180 KB | Output is correct |
19 | Correct | 672 ms | 3924 KB | Output is correct |
20 | Correct | 708 ms | 4180 KB | Output is correct |
21 | Correct | 711 ms | 4052 KB | Output is correct |
22 | Correct | 686 ms | 3980 KB | Output is correct |
23 | Correct | 673 ms | 3984 KB | Output is correct |
24 | Correct | 685 ms | 4052 KB | Output is correct |
25 | Correct | 702 ms | 4052 KB | Output is correct |
26 | Correct | 661 ms | 3924 KB | Output is correct |
27 | Correct | 708 ms | 4076 KB | Output is correct |
28 | Correct | 677 ms | 3816 KB | Output is correct |
29 | Correct | 697 ms | 4092 KB | Output is correct |
30 | Correct | 687 ms | 3944 KB | Output is correct |
31 | Correct | 679 ms | 4056 KB | Output is correct |
32 | Correct | 696 ms | 4056 KB | Output is correct |
33 | Correct | 695 ms | 3928 KB | Output is correct |
34 | Correct | 679 ms | 3896 KB | Output is correct |
35 | Correct | 727 ms | 4052 KB | Output is correct |
36 | Correct | 725 ms | 4052 KB | Output is correct |
37 | Correct | 716 ms | 4052 KB | Output is correct |
38 | Correct | 717 ms | 4052 KB | Output is correct |
39 | Correct | 728 ms | 3944 KB | Output is correct |
40 | Correct | 717 ms | 3948 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 1795 ms | 20316 KB | Output is correct |
12 | Execution timed out | 2060 ms | 16248 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |