Submission #853171

# Submission time Handle Problem Language Result Execution time Memory
853171 2023-09-23T15:25:23 Z Ahmed57 Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
1734 ms 20020 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int arr[(1<<n)];
    int sup[(1<<n)] = {0},super[(1<<n)] = {0};
    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 if(__builtin_popcount(one)<=6){
            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 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 548 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 548 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1469 ms 15068 KB Output is correct
12 Correct 1577 ms 14636 KB Output is correct
13 Correct 1555 ms 13956 KB Output is correct
14 Correct 1512 ms 14116 KB Output is correct
15 Correct 1467 ms 15368 KB Output is correct
16 Correct 1534 ms 14176 KB Output is correct
17 Correct 1511 ms 14440 KB Output is correct
18 Correct 1403 ms 16348 KB Output is correct
19 Correct 1469 ms 13056 KB Output is correct
20 Correct 1487 ms 14960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 548 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1469 ms 15068 KB Output is correct
12 Correct 1577 ms 14636 KB Output is correct
13 Correct 1555 ms 13956 KB Output is correct
14 Correct 1512 ms 14116 KB Output is correct
15 Correct 1467 ms 15368 KB Output is correct
16 Correct 1534 ms 14176 KB Output is correct
17 Correct 1511 ms 14440 KB Output is correct
18 Correct 1403 ms 16348 KB Output is correct
19 Correct 1469 ms 13056 KB Output is correct
20 Correct 1487 ms 14960 KB Output is correct
21 Correct 1513 ms 18092 KB Output is correct
22 Correct 1600 ms 18228 KB Output is correct
23 Correct 1734 ms 17624 KB Output is correct
24 Correct 1643 ms 17264 KB Output is correct
25 Correct 1558 ms 19260 KB Output is correct
26 Correct 1592 ms 17800 KB Output is correct
27 Correct 1612 ms 17528 KB Output is correct
28 Correct 1504 ms 20020 KB Output is correct
29 Correct 1529 ms 16332 KB Output is correct
30 Correct 1521 ms 18280 KB Output is correct
31 Correct 1627 ms 18416 KB Output is correct
32 Correct 1566 ms 18080 KB Output is correct
33 Correct 1527 ms 17108 KB Output is correct
34 Correct 1606 ms 17112 KB Output is correct
35 Correct 1668 ms 17660 KB Output is correct
36 Correct 1455 ms 16168 KB Output is correct
37 Correct 1553 ms 18188 KB Output is correct
38 Correct 1499 ms 16352 KB Output is correct
39 Correct 1577 ms 17800 KB Output is correct
40 Correct 1593 ms 17380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 548 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 125 ms 16192 KB Output is correct
12 Correct 126 ms 15964 KB Output is correct
13 Incorrect 131 ms 15936 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 548 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1469 ms 15068 KB Output is correct
12 Correct 1577 ms 14636 KB Output is correct
13 Correct 1555 ms 13956 KB Output is correct
14 Correct 1512 ms 14116 KB Output is correct
15 Correct 1467 ms 15368 KB Output is correct
16 Correct 1534 ms 14176 KB Output is correct
17 Correct 1511 ms 14440 KB Output is correct
18 Correct 1403 ms 16348 KB Output is correct
19 Correct 1469 ms 13056 KB Output is correct
20 Correct 1487 ms 14960 KB Output is correct
21 Correct 1513 ms 18092 KB Output is correct
22 Correct 1600 ms 18228 KB Output is correct
23 Correct 1734 ms 17624 KB Output is correct
24 Correct 1643 ms 17264 KB Output is correct
25 Correct 1558 ms 19260 KB Output is correct
26 Correct 1592 ms 17800 KB Output is correct
27 Correct 1612 ms 17528 KB Output is correct
28 Correct 1504 ms 20020 KB Output is correct
29 Correct 1529 ms 16332 KB Output is correct
30 Correct 1521 ms 18280 KB Output is correct
31 Correct 1627 ms 18416 KB Output is correct
32 Correct 1566 ms 18080 KB Output is correct
33 Correct 1527 ms 17108 KB Output is correct
34 Correct 1606 ms 17112 KB Output is correct
35 Correct 1668 ms 17660 KB Output is correct
36 Correct 1455 ms 16168 KB Output is correct
37 Correct 1553 ms 18188 KB Output is correct
38 Correct 1499 ms 16352 KB Output is correct
39 Correct 1577 ms 17800 KB Output is correct
40 Correct 1593 ms 17380 KB Output is correct
41 Correct 125 ms 16192 KB Output is correct
42 Correct 126 ms 15964 KB Output is correct
43 Incorrect 131 ms 15936 KB Output isn't correct
44 Halted 0 ms 0 KB -