Submission #853177

# Submission time Handle Problem Language Result Execution time Memory
853177 2023-09-23T15:32:26 Z Ahmed57 Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 53172 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int arr[(1<<20)];
    int sup[(1<<20)] = {0},super[(1<<20)] = {0};
signed main(){
    int n,m;
    cin>>n>>m;
    string s;cin>>s;
    for(int i = 0;i<(1<<n);i++){
        sup[i] = super[i] = arr[i] = (s[i]-'0');
    }
    for(int i = 0;i<n;i++){
        for(int mask = 0;mask<(1<<n);mask++){
            if(mask&(1<<i)){
                super[mask^(1<<i)]+=super[mask];
                sup[mask]+=sup[mask^(1<<i)];
            }
        }
    }
    while(m--){
        string s;cin>>s;
        int zero = 0 , one = 0 , qu = 0;
        for(int i = 0;i<n;i++){
            if(s[i]=='0')zero+=(1<<(n-i-1));
            else if(s[i]=='1')one+=(1<<(n-i-1));
            else qu+=(1<<(n-i-1));
        }
        long long all = 0;
        if(__builtin_popcount(qu)<=0){
            for(int mask = qu;;mask=(qu&(mask-1))){
                all+=arr[mask|one];
                //cout<<mask<<endl;
                if(mask==0)break;
            }
        }else if(__builtin_popcount(zero)<=6){
            for(int mask = zero;;mask=(zero&(mask-1))){
                if(__builtin_popcount(mask)&1)all-=super[mask|one];
                else all+=super[mask|one];
                if(mask==0)break;
            }
        }else {
            for(int mask = one;;mask=(one&(mask-1))){
                if(__builtin_popcount(mask)&1)all-=sup[mask^one^qu];
                else all+=sup[mask^one^qu];
                if(mask==0)break;
            }
        }
        cout<<all<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 3 ms 4440 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 3 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 3 ms 4440 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 3 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 1489 ms 8436 KB Output is correct
12 Correct 1486 ms 8272 KB Output is correct
13 Correct 1568 ms 7436 KB Output is correct
14 Correct 1519 ms 7516 KB Output is correct
15 Correct 1490 ms 8500 KB Output is correct
16 Correct 1521 ms 7772 KB Output is correct
17 Correct 1510 ms 7484 KB Output is correct
18 Correct 1412 ms 9476 KB Output is correct
19 Correct 1434 ms 6508 KB Output is correct
20 Correct 1490 ms 8188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 3 ms 4440 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 3 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 1489 ms 8436 KB Output is correct
12 Correct 1486 ms 8272 KB Output is correct
13 Correct 1568 ms 7436 KB Output is correct
14 Correct 1519 ms 7516 KB Output is correct
15 Correct 1490 ms 8500 KB Output is correct
16 Correct 1521 ms 7772 KB Output is correct
17 Correct 1510 ms 7484 KB Output is correct
18 Correct 1412 ms 9476 KB Output is correct
19 Correct 1434 ms 6508 KB Output is correct
20 Correct 1490 ms 8188 KB Output is correct
21 Correct 1520 ms 8568 KB Output is correct
22 Correct 1623 ms 8700 KB Output is correct
23 Correct 1796 ms 7900 KB Output is correct
24 Correct 1632 ms 7544 KB Output is correct
25 Correct 1632 ms 9552 KB Output is correct
26 Correct 1586 ms 7952 KB Output is correct
27 Correct 1618 ms 8300 KB Output is correct
28 Correct 1465 ms 10520 KB Output is correct
29 Correct 1586 ms 6424 KB Output is correct
30 Correct 1540 ms 9012 KB Output is correct
31 Correct 1615 ms 8528 KB Output is correct
32 Correct 1600 ms 8592 KB Output is correct
33 Correct 1521 ms 7340 KB Output is correct
34 Correct 1601 ms 7492 KB Output is correct
35 Correct 1592 ms 8036 KB Output is correct
36 Correct 1487 ms 6524 KB Output is correct
37 Correct 1496 ms 8824 KB Output is correct
38 Correct 1494 ms 6612 KB Output is correct
39 Correct 1622 ms 8100 KB Output is correct
40 Correct 1586 ms 7856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 3 ms 4440 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 3 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 130 ms 26200 KB Output is correct
12 Correct 128 ms 26432 KB Output is correct
13 Correct 155 ms 26180 KB Output is correct
14 Correct 145 ms 28692 KB Output is correct
15 Correct 130 ms 28480 KB Output is correct
16 Correct 137 ms 28248 KB Output is correct
17 Correct 178 ms 28408 KB Output is correct
18 Correct 120 ms 28492 KB Output is correct
19 Correct 129 ms 28244 KB Output is correct
20 Correct 131 ms 28480 KB Output is correct
21 Correct 145 ms 28652 KB Output is correct
22 Correct 154 ms 28244 KB Output is correct
23 Correct 124 ms 28592 KB Output is correct
24 Correct 138 ms 28228 KB Output is correct
25 Correct 141 ms 28224 KB Output is correct
26 Correct 123 ms 28384 KB Output is correct
27 Correct 131 ms 28476 KB Output is correct
28 Correct 130 ms 28160 KB Output is correct
29 Correct 173 ms 28224 KB Output is correct
30 Correct 161 ms 28224 KB Output is correct
31 Correct 127 ms 28232 KB Output is correct
32 Correct 162 ms 28252 KB Output is correct
33 Correct 166 ms 28568 KB Output is correct
34 Correct 121 ms 28252 KB Output is correct
35 Correct 157 ms 28228 KB Output is correct
36 Correct 144 ms 28356 KB Output is correct
37 Correct 147 ms 28224 KB Output is correct
38 Correct 164 ms 28236 KB Output is correct
39 Correct 147 ms 28308 KB Output is correct
40 Correct 167 ms 28264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 3 ms 4440 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 3 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 1489 ms 8436 KB Output is correct
12 Correct 1486 ms 8272 KB Output is correct
13 Correct 1568 ms 7436 KB Output is correct
14 Correct 1519 ms 7516 KB Output is correct
15 Correct 1490 ms 8500 KB Output is correct
16 Correct 1521 ms 7772 KB Output is correct
17 Correct 1510 ms 7484 KB Output is correct
18 Correct 1412 ms 9476 KB Output is correct
19 Correct 1434 ms 6508 KB Output is correct
20 Correct 1490 ms 8188 KB Output is correct
21 Correct 1520 ms 8568 KB Output is correct
22 Correct 1623 ms 8700 KB Output is correct
23 Correct 1796 ms 7900 KB Output is correct
24 Correct 1632 ms 7544 KB Output is correct
25 Correct 1632 ms 9552 KB Output is correct
26 Correct 1586 ms 7952 KB Output is correct
27 Correct 1618 ms 8300 KB Output is correct
28 Correct 1465 ms 10520 KB Output is correct
29 Correct 1586 ms 6424 KB Output is correct
30 Correct 1540 ms 9012 KB Output is correct
31 Correct 1615 ms 8528 KB Output is correct
32 Correct 1600 ms 8592 KB Output is correct
33 Correct 1521 ms 7340 KB Output is correct
34 Correct 1601 ms 7492 KB Output is correct
35 Correct 1592 ms 8036 KB Output is correct
36 Correct 1487 ms 6524 KB Output is correct
37 Correct 1496 ms 8824 KB Output is correct
38 Correct 1494 ms 6612 KB Output is correct
39 Correct 1622 ms 8100 KB Output is correct
40 Correct 1586 ms 7856 KB Output is correct
41 Correct 130 ms 26200 KB Output is correct
42 Correct 128 ms 26432 KB Output is correct
43 Correct 155 ms 26180 KB Output is correct
44 Correct 145 ms 28692 KB Output is correct
45 Correct 130 ms 28480 KB Output is correct
46 Correct 137 ms 28248 KB Output is correct
47 Correct 178 ms 28408 KB Output is correct
48 Correct 120 ms 28492 KB Output is correct
49 Correct 129 ms 28244 KB Output is correct
50 Correct 131 ms 28480 KB Output is correct
51 Correct 145 ms 28652 KB Output is correct
52 Correct 154 ms 28244 KB Output is correct
53 Correct 124 ms 28592 KB Output is correct
54 Correct 138 ms 28228 KB Output is correct
55 Correct 141 ms 28224 KB Output is correct
56 Correct 123 ms 28384 KB Output is correct
57 Correct 131 ms 28476 KB Output is correct
58 Correct 130 ms 28160 KB Output is correct
59 Correct 173 ms 28224 KB Output is correct
60 Correct 161 ms 28224 KB Output is correct
61 Correct 127 ms 28232 KB Output is correct
62 Correct 162 ms 28252 KB Output is correct
63 Correct 166 ms 28568 KB Output is correct
64 Correct 121 ms 28252 KB Output is correct
65 Correct 157 ms 28228 KB Output is correct
66 Correct 144 ms 28356 KB Output is correct
67 Correct 147 ms 28224 KB Output is correct
68 Correct 164 ms 28236 KB Output is correct
69 Correct 147 ms 28308 KB Output is correct
70 Correct 167 ms 28264 KB Output is correct
71 Correct 1763 ms 53172 KB Output is correct
72 Correct 1841 ms 52956 KB Output is correct
73 Execution timed out 2028 ms 51428 KB Time limit exceeded
74 Halted 0 ms 0 KB -