Submission #340551

# Submission time Handle Problem Language Result Execution time Memory
340551 2020-12-27T22:57:52 Z couplefire Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1900 ms 55684 KB
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1594323

int len, q;
int dp[MAXN];
string s;
int ans[MAXN];
int pw[21];
int lowbit[MAXN];
int mp[MAXN];
int counter;
bool isSub[2187][128];
int p1[MAXN], p2[MAXN];

int main(){
    // freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> len >> q >> s;
    for(int i = 0; i<2187; i++){
        for(int j = 0; j<128; j++){
            isSub[i][j] = 1;
            int c1 = i, c2 = j;
            for(int k = 0; k < 7; k++){
                if((c1%3 != 2 && c2%2 != c1%3)) isSub[i][j] = 0;
                c1 /= 3, c2 /= 2;
            }
        }
    }
    pw[0] = 1; for(int i = 1; i<=20; i++) pw[i] = pw[i-1]*3;
    lowbit[0] = lowbit[1] = MAXN;
    for(int i = 2; i<MAXN; i++){
        if(i%3 == 2) lowbit[i] = 0;
        else lowbit[i] = lowbit[i/3]+1;
    }
    for(int i = 0; i<MAXN; i++){
        if(lowbit[i] >= MAXN) mp[counter++] = i;
    }
    for(int i = 0; i<q; i++){
        string ss; cin >> ss;
        reverse(ss.begin(), ss.end());
        int cur2 = 0;
        for(int j = 0; j<min(7, len); j++){
            if(ss[j] == '?') cur2 += pw[j]*2;
            else cur2 += pw[j]*(ss[j]-'0');
        }
        p2[i] = cur2;
        int cur1 = 0;
        for(int j = 7; j<len; j++){
            if(ss[j] == '?') cur1 += pw[j-7]*2;
            else cur1 += pw[j-7]*(ss[j]-'0');
        }
        p1[i] = cur1;
    }
    // for(int i = 0; i<100; i++) cout << lowbit[i] << " ";
    // cout << endl;
    for(int i = 0; i < min(128, (int)s.length()); i++){
        memset(dp, 0, sizeof dp);
        for(int j = 0, end = (1<<(max(len-7, 0))); j<end; j++) dp[mp[j]] = s[(j<<7)+i]-'0';
        for(int j = 0; j<((len >= 7) ? pw[len-7] : 1); j++){
            if(lowbit[j] < MAXN) dp[j] = dp[j-pw[lowbit[j]]]+dp[j-pw[lowbit[j]]*2];
        }
        for(int j = 0; j<q; j++){
            if(isSub[p2[j]][i]) ans[j] += dp[p1[j]];
        }
    }
    for(int i = 0; i<q; i++) cout << ans[i] << " ";
    cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13184 KB Output is correct
2 Correct 65 ms 13164 KB Output is correct
3 Correct 69 ms 13292 KB Output is correct
4 Correct 72 ms 13164 KB Output is correct
5 Correct 67 ms 13164 KB Output is correct
6 Correct 75 ms 13164 KB Output is correct
7 Correct 69 ms 13184 KB Output is correct
8 Correct 67 ms 13164 KB Output is correct
9 Correct 63 ms 13304 KB Output is correct
10 Correct 67 ms 13164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13184 KB Output is correct
2 Correct 65 ms 13164 KB Output is correct
3 Correct 69 ms 13292 KB Output is correct
4 Correct 72 ms 13164 KB Output is correct
5 Correct 67 ms 13164 KB Output is correct
6 Correct 75 ms 13164 KB Output is correct
7 Correct 69 ms 13184 KB Output is correct
8 Correct 67 ms 13164 KB Output is correct
9 Correct 63 ms 13304 KB Output is correct
10 Correct 67 ms 13164 KB Output is correct
11 Correct 718 ms 39548 KB Output is correct
12 Correct 793 ms 39456 KB Output is correct
13 Correct 691 ms 38764 KB Output is correct
14 Correct 697 ms 38764 KB Output is correct
15 Correct 818 ms 39788 KB Output is correct
16 Correct 718 ms 39012 KB Output is correct
17 Correct 733 ms 38892 KB Output is correct
18 Correct 479 ms 40812 KB Output is correct
19 Correct 573 ms 37740 KB Output is correct
20 Correct 762 ms 39428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13184 KB Output is correct
2 Correct 65 ms 13164 KB Output is correct
3 Correct 69 ms 13292 KB Output is correct
4 Correct 72 ms 13164 KB Output is correct
5 Correct 67 ms 13164 KB Output is correct
6 Correct 75 ms 13164 KB Output is correct
7 Correct 69 ms 13184 KB Output is correct
8 Correct 67 ms 13164 KB Output is correct
9 Correct 63 ms 13304 KB Output is correct
10 Correct 67 ms 13164 KB Output is correct
11 Correct 718 ms 39548 KB Output is correct
12 Correct 793 ms 39456 KB Output is correct
13 Correct 691 ms 38764 KB Output is correct
14 Correct 697 ms 38764 KB Output is correct
15 Correct 818 ms 39788 KB Output is correct
16 Correct 718 ms 39012 KB Output is correct
17 Correct 733 ms 38892 KB Output is correct
18 Correct 479 ms 40812 KB Output is correct
19 Correct 573 ms 37740 KB Output is correct
20 Correct 762 ms 39428 KB Output is correct
21 Correct 767 ms 42732 KB Output is correct
22 Correct 818 ms 42860 KB Output is correct
23 Correct 746 ms 41964 KB Output is correct
24 Correct 761 ms 41708 KB Output is correct
25 Correct 880 ms 43884 KB Output is correct
26 Correct 738 ms 42092 KB Output is correct
27 Correct 736 ms 42220 KB Output is correct
28 Correct 483 ms 44780 KB Output is correct
29 Correct 620 ms 40604 KB Output is correct
30 Correct 786 ms 42860 KB Output is correct
31 Correct 761 ms 42732 KB Output is correct
32 Correct 735 ms 42732 KB Output is correct
33 Correct 681 ms 41708 KB Output is correct
34 Correct 746 ms 41708 KB Output is correct
35 Correct 782 ms 42348 KB Output is correct
36 Correct 477 ms 40684 KB Output is correct
37 Correct 749 ms 42732 KB Output is correct
38 Correct 596 ms 40684 KB Output is correct
39 Correct 746 ms 41964 KB Output is correct
40 Correct 752 ms 41708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13184 KB Output is correct
2 Correct 65 ms 13164 KB Output is correct
3 Correct 69 ms 13292 KB Output is correct
4 Correct 72 ms 13164 KB Output is correct
5 Correct 67 ms 13164 KB Output is correct
6 Correct 75 ms 13164 KB Output is correct
7 Correct 69 ms 13184 KB Output is correct
8 Correct 67 ms 13164 KB Output is correct
9 Correct 63 ms 13304 KB Output is correct
10 Correct 67 ms 13164 KB Output is correct
11 Correct 615 ms 17296 KB Output is correct
12 Correct 606 ms 17168 KB Output is correct
13 Correct 615 ms 17168 KB Output is correct
14 Correct 632 ms 17216 KB Output is correct
15 Correct 629 ms 17424 KB Output is correct
16 Correct 620 ms 17168 KB Output is correct
17 Correct 636 ms 17168 KB Output is correct
18 Correct 583 ms 17424 KB Output is correct
19 Correct 588 ms 17040 KB Output is correct
20 Correct 625 ms 17296 KB Output is correct
21 Correct 641 ms 17288 KB Output is correct
22 Correct 629 ms 17168 KB Output is correct
23 Correct 611 ms 17168 KB Output is correct
24 Correct 629 ms 17224 KB Output is correct
25 Correct 630 ms 17296 KB Output is correct
26 Correct 589 ms 17040 KB Output is correct
27 Correct 613 ms 17168 KB Output is correct
28 Correct 593 ms 17040 KB Output is correct
29 Correct 633 ms 17168 KB Output is correct
30 Correct 630 ms 17168 KB Output is correct
31 Correct 612 ms 17168 KB Output is correct
32 Correct 630 ms 17168 KB Output is correct
33 Correct 624 ms 17168 KB Output is correct
34 Correct 585 ms 17040 KB Output is correct
35 Correct 641 ms 17168 KB Output is correct
36 Correct 626 ms 17168 KB Output is correct
37 Correct 626 ms 17168 KB Output is correct
38 Correct 638 ms 17168 KB Output is correct
39 Correct 626 ms 17168 KB Output is correct
40 Correct 628 ms 17168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13184 KB Output is correct
2 Correct 65 ms 13164 KB Output is correct
3 Correct 69 ms 13292 KB Output is correct
4 Correct 72 ms 13164 KB Output is correct
5 Correct 67 ms 13164 KB Output is correct
6 Correct 75 ms 13164 KB Output is correct
7 Correct 69 ms 13184 KB Output is correct
8 Correct 67 ms 13164 KB Output is correct
9 Correct 63 ms 13304 KB Output is correct
10 Correct 67 ms 13164 KB Output is correct
11 Correct 718 ms 39548 KB Output is correct
12 Correct 793 ms 39456 KB Output is correct
13 Correct 691 ms 38764 KB Output is correct
14 Correct 697 ms 38764 KB Output is correct
15 Correct 818 ms 39788 KB Output is correct
16 Correct 718 ms 39012 KB Output is correct
17 Correct 733 ms 38892 KB Output is correct
18 Correct 479 ms 40812 KB Output is correct
19 Correct 573 ms 37740 KB Output is correct
20 Correct 762 ms 39428 KB Output is correct
21 Correct 767 ms 42732 KB Output is correct
22 Correct 818 ms 42860 KB Output is correct
23 Correct 746 ms 41964 KB Output is correct
24 Correct 761 ms 41708 KB Output is correct
25 Correct 880 ms 43884 KB Output is correct
26 Correct 738 ms 42092 KB Output is correct
27 Correct 736 ms 42220 KB Output is correct
28 Correct 483 ms 44780 KB Output is correct
29 Correct 620 ms 40604 KB Output is correct
30 Correct 786 ms 42860 KB Output is correct
31 Correct 761 ms 42732 KB Output is correct
32 Correct 735 ms 42732 KB Output is correct
33 Correct 681 ms 41708 KB Output is correct
34 Correct 746 ms 41708 KB Output is correct
35 Correct 782 ms 42348 KB Output is correct
36 Correct 477 ms 40684 KB Output is correct
37 Correct 749 ms 42732 KB Output is correct
38 Correct 596 ms 40684 KB Output is correct
39 Correct 746 ms 41964 KB Output is correct
40 Correct 752 ms 41708 KB Output is correct
41 Correct 615 ms 17296 KB Output is correct
42 Correct 606 ms 17168 KB Output is correct
43 Correct 615 ms 17168 KB Output is correct
44 Correct 632 ms 17216 KB Output is correct
45 Correct 629 ms 17424 KB Output is correct
46 Correct 620 ms 17168 KB Output is correct
47 Correct 636 ms 17168 KB Output is correct
48 Correct 583 ms 17424 KB Output is correct
49 Correct 588 ms 17040 KB Output is correct
50 Correct 625 ms 17296 KB Output is correct
51 Correct 641 ms 17288 KB Output is correct
52 Correct 629 ms 17168 KB Output is correct
53 Correct 611 ms 17168 KB Output is correct
54 Correct 629 ms 17224 KB Output is correct
55 Correct 630 ms 17296 KB Output is correct
56 Correct 589 ms 17040 KB Output is correct
57 Correct 613 ms 17168 KB Output is correct
58 Correct 593 ms 17040 KB Output is correct
59 Correct 633 ms 17168 KB Output is correct
60 Correct 630 ms 17168 KB Output is correct
61 Correct 612 ms 17168 KB Output is correct
62 Correct 630 ms 17168 KB Output is correct
63 Correct 624 ms 17168 KB Output is correct
64 Correct 585 ms 17040 KB Output is correct
65 Correct 641 ms 17168 KB Output is correct
66 Correct 626 ms 17168 KB Output is correct
67 Correct 626 ms 17168 KB Output is correct
68 Correct 638 ms 17168 KB Output is correct
69 Correct 626 ms 17168 KB Output is correct
70 Correct 628 ms 17168 KB Output is correct
71 Correct 1366 ms 52752 KB Output is correct
72 Correct 1435 ms 52912 KB Output is correct
73 Correct 1497 ms 51420 KB Output is correct
74 Correct 1689 ms 51776 KB Output is correct
75 Correct 1791 ms 53896 KB Output is correct
76 Correct 1740 ms 51984 KB Output is correct
77 Correct 1761 ms 52024 KB Output is correct
78 Correct 1045 ms 55684 KB Output is correct
79 Correct 1154 ms 49760 KB Output is correct
80 Correct 1400 ms 52856 KB Output is correct
81 Correct 1900 ms 52968 KB Output is correct
82 Correct 1714 ms 51800 KB Output is correct
83 Correct 1279 ms 50876 KB Output is correct
84 Correct 1665 ms 51784 KB Output is correct
85 Correct 1757 ms 51996 KB Output is correct
86 Correct 1022 ms 49788 KB Output is correct
87 Correct 1411 ms 52904 KB Output is correct
88 Correct 1164 ms 49616 KB Output is correct
89 Correct 1500 ms 51392 KB Output is correct
90 Correct 1632 ms 51864 KB Output is correct
91 Correct 1285 ms 51228 KB Output is correct
92 Correct 1765 ms 52032 KB Output is correct
93 Correct 1782 ms 51884 KB Output is correct
94 Correct 1028 ms 49760 KB Output is correct
95 Correct 1697 ms 51808 KB Output is correct
96 Correct 1702 ms 51832 KB Output is correct
97 Correct 1709 ms 51880 KB Output is correct
98 Correct 1721 ms 51904 KB Output is correct
99 Correct 1756 ms 51868 KB Output is correct
100 Correct 1680 ms 51988 KB Output is correct