Submission #135184

# Submission time Handle Problem Language Result Execution time Memory
135184 2019-07-23T19:01:55 Z duality Snake Escaping (JOI18_snake_escaping) C++11
58 / 100
2000 ms 22108 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];
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

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %s",&L,&Q,S);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:24:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",T),queries[i].i = i;
         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 1896 ms 22108 KB Output is correct
12 Execution timed out 2047 ms 17912 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 1896 ms 22108 KB Output is correct
12 Execution timed out 2047 ms 17912 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 895 ms 4356 KB Output is correct
12 Correct 904 ms 4316 KB Output is correct
13 Correct 889 ms 4088 KB Output is correct
14 Correct 869 ms 4064 KB Output is correct
15 Correct 950 ms 4216 KB Output is correct
16 Correct 884 ms 4216 KB Output is correct
17 Correct 881 ms 4088 KB Output is correct
18 Correct 960 ms 4344 KB Output is correct
19 Correct 852 ms 3960 KB Output is correct
20 Correct 897 ms 4196 KB Output is correct
21 Correct 907 ms 4088 KB Output is correct
22 Correct 891 ms 4180 KB Output is correct
23 Correct 875 ms 4216 KB Output is correct
24 Correct 864 ms 4216 KB Output is correct
25 Correct 872 ms 4172 KB Output is correct
26 Correct 844 ms 3996 KB Output is correct
27 Correct 887 ms 4196 KB Output is correct
28 Correct 859 ms 3944 KB Output is correct
29 Correct 863 ms 4112 KB Output is correct
30 Correct 865 ms 4088 KB Output is correct
31 Correct 859 ms 4068 KB Output is correct
32 Correct 924 ms 4116 KB Output is correct
33 Correct 881 ms 4088 KB Output is correct
34 Correct 853 ms 3940 KB Output is correct
35 Correct 908 ms 4108 KB Output is correct
36 Correct 909 ms 4060 KB Output is correct
37 Correct 1082 ms 4068 KB Output is correct
38 Correct 918 ms 4060 KB Output is correct
39 Correct 922 ms 4076 KB Output is correct
40 Correct 912 ms 4108 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 1896 ms 22108 KB Output is correct
12 Execution timed out 2047 ms 17912 KB Time limit exceeded
13 Halted 0 ms 0 KB -