Submission #848738

# Submission time Handle Problem Language Result Execution time Memory
848738 2023-09-13T12:14:39 Z socpite Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1636 ms 32128 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = (1<<20);

int n, q;

int sub[maxn], super[maxn], val[maxn];

int gt(char x){
    if(x == '0' || x == '1')return x-'0';
    else return 2;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> q;
    for(int i = 0; i < (1<<n); i++){
        char x;
        cin >> x;
        sub[i] = super[i] = val[i] = x-'0';
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < (1<<n); j++){
            if(j&(1<<i)){
                super[j^(1<<i)]+=super[j];
                sub[j]+=sub[j^(1<<i)];
            }
        }
    }
    while(q--){
        string str;
        cin >> str;
        reverse(str.begin(), str.end());
        int mask[3] = {0, 0, 0};
        long long ans = 0;
        for(int i = 0; i < n; i++){
            mask[gt(str[i])]|=(1<<i);
        }
        if(__builtin_popcount(mask[1]) <= 6){
            for(int i = mask[1];;i=(i-1)&mask[1]){
                if(__builtin_popcount(i)&1)ans -= sub[mask[2]^mask[1]^i];
                else ans += sub[mask[2]^mask[1]^i];
                if(!i)break;
            }
        }
        else if(__builtin_popcount(mask[2]) <= 6){
            for(int i = mask[2];;i=(i-1)&mask[2]){
                ans += val[i^mask[1]];
                if(!i)break;
            }
        }
        else {
            for(int i = mask[0];;i=(i-1)&mask[0]){
                if(__builtin_popcount(i)&1)ans -= super[mask[1]^i];
                else ans += super[mask[1]^i];
                if(!i)break;
            }
        }
        cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1319 ms 8500 KB Output is correct
12 Correct 1240 ms 8168 KB Output is correct
13 Correct 1234 ms 7508 KB Output is correct
14 Correct 1255 ms 7604 KB Output is correct
15 Correct 1233 ms 8796 KB Output is correct
16 Correct 1274 ms 7600 KB Output is correct
17 Correct 1250 ms 7700 KB Output is correct
18 Correct 1219 ms 9408 KB Output is correct
19 Correct 1295 ms 10328 KB Output is correct
20 Correct 1284 ms 11624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1319 ms 8500 KB Output is correct
12 Correct 1240 ms 8168 KB Output is correct
13 Correct 1234 ms 7508 KB Output is correct
14 Correct 1255 ms 7604 KB Output is correct
15 Correct 1233 ms 8796 KB Output is correct
16 Correct 1274 ms 7600 KB Output is correct
17 Correct 1250 ms 7700 KB Output is correct
18 Correct 1219 ms 9408 KB Output is correct
19 Correct 1295 ms 10328 KB Output is correct
20 Correct 1284 ms 11624 KB Output is correct
21 Correct 1420 ms 13140 KB Output is correct
22 Correct 1213 ms 13320 KB Output is correct
23 Correct 1295 ms 12420 KB Output is correct
24 Correct 1289 ms 12080 KB Output is correct
25 Correct 1274 ms 14024 KB Output is correct
26 Correct 1295 ms 12744 KB Output is correct
27 Correct 1337 ms 12868 KB Output is correct
28 Correct 1234 ms 15256 KB Output is correct
29 Correct 1224 ms 11264 KB Output is correct
30 Correct 1390 ms 13316 KB Output is correct
31 Correct 1254 ms 13200 KB Output is correct
32 Correct 1273 ms 13196 KB Output is correct
33 Correct 1220 ms 11848 KB Output is correct
34 Correct 1298 ms 12164 KB Output is correct
35 Correct 1444 ms 12612 KB Output is correct
36 Correct 1307 ms 10988 KB Output is correct
37 Correct 1255 ms 12984 KB Output is correct
38 Correct 1325 ms 11152 KB Output is correct
39 Correct 1477 ms 12284 KB Output is correct
40 Correct 1311 ms 12596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 98 ms 12760 KB Output is correct
12 Correct 111 ms 12808 KB Output is correct
13 Correct 107 ms 13392 KB Output is correct
14 Correct 128 ms 13344 KB Output is correct
15 Correct 104 ms 13392 KB Output is correct
16 Correct 112 ms 13436 KB Output is correct
17 Correct 109 ms 13396 KB Output is correct
18 Correct 98 ms 13640 KB Output is correct
19 Correct 108 ms 13140 KB Output is correct
20 Correct 106 ms 13392 KB Output is correct
21 Correct 103 ms 13476 KB Output is correct
22 Correct 113 ms 13428 KB Output is correct
23 Correct 103 ms 13176 KB Output is correct
24 Correct 117 ms 13392 KB Output is correct
25 Correct 115 ms 13392 KB Output is correct
26 Correct 104 ms 13524 KB Output is correct
27 Correct 104 ms 13480 KB Output is correct
28 Correct 108 ms 13564 KB Output is correct
29 Correct 104 ms 13424 KB Output is correct
30 Correct 111 ms 13396 KB Output is correct
31 Correct 101 ms 13296 KB Output is correct
32 Correct 109 ms 13392 KB Output is correct
33 Correct 113 ms 13396 KB Output is correct
34 Correct 100 ms 13140 KB Output is correct
35 Correct 120 ms 13284 KB Output is correct
36 Correct 112 ms 13272 KB Output is correct
37 Correct 106 ms 13348 KB Output is correct
38 Correct 119 ms 13396 KB Output is correct
39 Correct 118 ms 13360 KB Output is correct
40 Correct 107 ms 13452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1319 ms 8500 KB Output is correct
12 Correct 1240 ms 8168 KB Output is correct
13 Correct 1234 ms 7508 KB Output is correct
14 Correct 1255 ms 7604 KB Output is correct
15 Correct 1233 ms 8796 KB Output is correct
16 Correct 1274 ms 7600 KB Output is correct
17 Correct 1250 ms 7700 KB Output is correct
18 Correct 1219 ms 9408 KB Output is correct
19 Correct 1295 ms 10328 KB Output is correct
20 Correct 1284 ms 11624 KB Output is correct
21 Correct 1420 ms 13140 KB Output is correct
22 Correct 1213 ms 13320 KB Output is correct
23 Correct 1295 ms 12420 KB Output is correct
24 Correct 1289 ms 12080 KB Output is correct
25 Correct 1274 ms 14024 KB Output is correct
26 Correct 1295 ms 12744 KB Output is correct
27 Correct 1337 ms 12868 KB Output is correct
28 Correct 1234 ms 15256 KB Output is correct
29 Correct 1224 ms 11264 KB Output is correct
30 Correct 1390 ms 13316 KB Output is correct
31 Correct 1254 ms 13200 KB Output is correct
32 Correct 1273 ms 13196 KB Output is correct
33 Correct 1220 ms 11848 KB Output is correct
34 Correct 1298 ms 12164 KB Output is correct
35 Correct 1444 ms 12612 KB Output is correct
36 Correct 1307 ms 10988 KB Output is correct
37 Correct 1255 ms 12984 KB Output is correct
38 Correct 1325 ms 11152 KB Output is correct
39 Correct 1477 ms 12284 KB Output is correct
40 Correct 1311 ms 12596 KB Output is correct
41 Correct 98 ms 12760 KB Output is correct
42 Correct 111 ms 12808 KB Output is correct
43 Correct 107 ms 13392 KB Output is correct
44 Correct 128 ms 13344 KB Output is correct
45 Correct 104 ms 13392 KB Output is correct
46 Correct 112 ms 13436 KB Output is correct
47 Correct 109 ms 13396 KB Output is correct
48 Correct 98 ms 13640 KB Output is correct
49 Correct 108 ms 13140 KB Output is correct
50 Correct 106 ms 13392 KB Output is correct
51 Correct 103 ms 13476 KB Output is correct
52 Correct 113 ms 13428 KB Output is correct
53 Correct 103 ms 13176 KB Output is correct
54 Correct 117 ms 13392 KB Output is correct
55 Correct 115 ms 13392 KB Output is correct
56 Correct 104 ms 13524 KB Output is correct
57 Correct 104 ms 13480 KB Output is correct
58 Correct 108 ms 13564 KB Output is correct
59 Correct 104 ms 13424 KB Output is correct
60 Correct 111 ms 13396 KB Output is correct
61 Correct 101 ms 13296 KB Output is correct
62 Correct 109 ms 13392 KB Output is correct
63 Correct 113 ms 13396 KB Output is correct
64 Correct 100 ms 13140 KB Output is correct
65 Correct 120 ms 13284 KB Output is correct
66 Correct 112 ms 13272 KB Output is correct
67 Correct 106 ms 13348 KB Output is correct
68 Correct 119 ms 13396 KB Output is correct
69 Correct 118 ms 13360 KB Output is correct
70 Correct 107 ms 13452 KB Output is correct
71 Correct 1407 ms 24828 KB Output is correct
72 Correct 1383 ms 24892 KB Output is correct
73 Correct 1438 ms 23680 KB Output is correct
74 Correct 1583 ms 23992 KB Output is correct
75 Correct 1426 ms 26128 KB Output is correct
76 Correct 1636 ms 24288 KB Output is correct
77 Correct 1555 ms 28312 KB Output is correct
78 Correct 1345 ms 32128 KB Output is correct
79 Correct 1332 ms 25780 KB Output is correct
80 Correct 1379 ms 29156 KB Output is correct
81 Correct 1465 ms 29148 KB Output is correct
82 Correct 1626 ms 27940 KB Output is correct
83 Correct 1373 ms 27140 KB Output is correct
84 Correct 1470 ms 28312 KB Output is correct
85 Correct 1474 ms 28248 KB Output is correct
86 Correct 1347 ms 25964 KB Output is correct
87 Correct 1373 ms 29208 KB Output is correct
88 Correct 1349 ms 26048 KB Output is correct
89 Correct 1437 ms 28172 KB Output is correct
90 Correct 1467 ms 27992 KB Output is correct
91 Correct 1398 ms 27500 KB Output is correct
92 Correct 1597 ms 28148 KB Output is correct
93 Correct 1518 ms 28448 KB Output is correct
94 Correct 1330 ms 26056 KB Output is correct
95 Correct 1564 ms 28072 KB Output is correct
96 Correct 1468 ms 28508 KB Output is correct
97 Correct 1592 ms 28388 KB Output is correct
98 Correct 1592 ms 28144 KB Output is correct
99 Correct 1491 ms 28264 KB Output is correct
100 Correct 1543 ms 28328 KB Output is correct