# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
135188 | 2019-07-23T19:06:40 Z | duality | Snake Escaping (JOI18_snake_escaping) | C++11 | 2000 ms | 20088 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; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") 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]; 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) == 2) num[i] |= (1 << j); 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] & (1 << j)) 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 | 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 | 3 ms | 380 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 | 6 ms | 376 KB | Output is correct |
9 | Correct | 4 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 | 3 ms | 380 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 | 6 ms | 376 KB | Output is correct |
9 | Correct | 4 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 1949 ms | 20088 KB | Output is correct |
12 | Execution timed out | 2058 ms | 16032 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 | 3 ms | 380 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 | 6 ms | 376 KB | Output is correct |
9 | Correct | 4 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 1949 ms | 20088 KB | Output is correct |
12 | Execution timed out | 2058 ms | 16032 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 | 3 ms | 380 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 | 6 ms | 376 KB | Output is correct |
9 | Correct | 4 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 847 ms | 2920 KB | Output is correct |
12 | Correct | 860 ms | 2956 KB | Output is correct |
13 | Correct | 819 ms | 2936 KB | Output is correct |
14 | Correct | 829 ms | 2808 KB | Output is correct |
15 | Correct | 920 ms | 3064 KB | Output is correct |
16 | Correct | 836 ms | 2824 KB | Output is correct |
17 | Correct | 835 ms | 2808 KB | Output is correct |
18 | Correct | 915 ms | 3080 KB | Output is correct |
19 | Correct | 811 ms | 2812 KB | Output is correct |
20 | Correct | 857 ms | 3064 KB | Output is correct |
21 | Correct | 866 ms | 2928 KB | Output is correct |
22 | Correct | 836 ms | 2796 KB | Output is correct |
23 | Correct | 816 ms | 2800 KB | Output is correct |
24 | Correct | 826 ms | 2852 KB | Output is correct |
25 | Correct | 834 ms | 2808 KB | Output is correct |
26 | Correct | 809 ms | 2716 KB | Output is correct |
27 | Correct | 846 ms | 2936 KB | Output is correct |
28 | Correct | 810 ms | 2680 KB | Output is correct |
29 | Correct | 832 ms | 2916 KB | Output is correct |
30 | Correct | 827 ms | 2796 KB | Output is correct |
31 | Correct | 821 ms | 2828 KB | Output is correct |
32 | Correct | 834 ms | 2936 KB | Output is correct |
33 | Correct | 836 ms | 2808 KB | Output is correct |
34 | Correct | 830 ms | 2680 KB | Output is correct |
35 | Correct | 870 ms | 2800 KB | Output is correct |
36 | Correct | 872 ms | 2936 KB | Output is correct |
37 | Correct | 868 ms | 2808 KB | Output is correct |
38 | Correct | 870 ms | 2780 KB | Output is correct |
39 | Correct | 875 ms | 2936 KB | Output is correct |
40 | Correct | 869 ms | 2908 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 | 3 ms | 380 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 | 6 ms | 376 KB | Output is correct |
9 | Correct | 4 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 1949 ms | 20088 KB | Output is correct |
12 | Execution timed out | 2058 ms | 16032 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |