Submission #135181

# Submission time Handle Problem Language Result Execution time Memory
135181 2019-07-23T18:54:14 Z duality Snake Escaping (JOI18_snake_escaping) C++11
22 / 100
2000 ms 35832 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 = 7;
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

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 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 603 ms 30796 KB Output is correct
12 Correct 659 ms 30408 KB Output is correct
13 Correct 504 ms 29604 KB Output is correct
14 Correct 515 ms 29804 KB Output is correct
15 Correct 709 ms 30744 KB Output is correct
16 Correct 563 ms 29944 KB Output is correct
17 Correct 682 ms 29848 KB Output is correct
18 Correct 651 ms 31824 KB Output is correct
19 Correct 428 ms 28780 KB Output is correct
20 Correct 654 ms 30564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 603 ms 30796 KB Output is correct
12 Correct 659 ms 30408 KB Output is correct
13 Correct 504 ms 29604 KB Output is correct
14 Correct 515 ms 29804 KB Output is correct
15 Correct 709 ms 30744 KB Output is correct
16 Correct 563 ms 29944 KB Output is correct
17 Correct 682 ms 29848 KB Output is correct
18 Correct 651 ms 31824 KB Output is correct
19 Correct 428 ms 28780 KB Output is correct
20 Correct 654 ms 30564 KB Output is correct
21 Correct 669 ms 33760 KB Output is correct
22 Correct 668 ms 33920 KB Output is correct
23 Correct 552 ms 32872 KB Output is correct
24 Correct 553 ms 32844 KB Output is correct
25 Correct 773 ms 34784 KB Output is correct
26 Correct 603 ms 33256 KB Output is correct
27 Correct 597 ms 33132 KB Output is correct
28 Correct 674 ms 35832 KB Output is correct
29 Correct 466 ms 31736 KB Output is correct
30 Correct 707 ms 33840 KB Output is correct
31 Correct 633 ms 33784 KB Output is correct
32 Correct 594 ms 33784 KB Output is correct
33 Correct 527 ms 32708 KB Output is correct
34 Correct 675 ms 32848 KB Output is correct
35 Correct 632 ms 33360 KB Output is correct
36 Correct 450 ms 31736 KB Output is correct
37 Correct 610 ms 33784 KB Output is correct
38 Correct 547 ms 31844 KB Output is correct
39 Correct 566 ms 32896 KB Output is correct
40 Correct 579 ms 32724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Execution timed out 2036 ms 16608 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 603 ms 30796 KB Output is correct
12 Correct 659 ms 30408 KB Output is correct
13 Correct 504 ms 29604 KB Output is correct
14 Correct 515 ms 29804 KB Output is correct
15 Correct 709 ms 30744 KB Output is correct
16 Correct 563 ms 29944 KB Output is correct
17 Correct 682 ms 29848 KB Output is correct
18 Correct 651 ms 31824 KB Output is correct
19 Correct 428 ms 28780 KB Output is correct
20 Correct 654 ms 30564 KB Output is correct
21 Correct 669 ms 33760 KB Output is correct
22 Correct 668 ms 33920 KB Output is correct
23 Correct 552 ms 32872 KB Output is correct
24 Correct 553 ms 32844 KB Output is correct
25 Correct 773 ms 34784 KB Output is correct
26 Correct 603 ms 33256 KB Output is correct
27 Correct 597 ms 33132 KB Output is correct
28 Correct 674 ms 35832 KB Output is correct
29 Correct 466 ms 31736 KB Output is correct
30 Correct 707 ms 33840 KB Output is correct
31 Correct 633 ms 33784 KB Output is correct
32 Correct 594 ms 33784 KB Output is correct
33 Correct 527 ms 32708 KB Output is correct
34 Correct 675 ms 32848 KB Output is correct
35 Correct 632 ms 33360 KB Output is correct
36 Correct 450 ms 31736 KB Output is correct
37 Correct 610 ms 33784 KB Output is correct
38 Correct 547 ms 31844 KB Output is correct
39 Correct 566 ms 32896 KB Output is correct
40 Correct 579 ms 32724 KB Output is correct
41 Execution timed out 2036 ms 16608 KB Time limit exceeded
42 Halted 0 ms 0 KB -