Submission #853188

# Submission time Handle Problem Language Result Execution time Memory
853188 2023-09-23T15:40:45 Z Ahmed57 Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 22000 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
int arr[(1<<20)];
    int sup[(1<<20)] = {0},super[(1<<20)] = {0};
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    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 4444 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 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 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 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 1276 ms 8420 KB Output is correct
12 Correct 1382 ms 8164 KB Output is correct
13 Correct 1336 ms 7512 KB Output is correct
14 Correct 1285 ms 7312 KB Output is correct
15 Correct 1275 ms 8488 KB Output is correct
16 Correct 1282 ms 7724 KB Output is correct
17 Correct 1298 ms 7760 KB Output is correct
18 Correct 1200 ms 9528 KB Output is correct
19 Correct 1226 ms 6408 KB Output is correct
20 Correct 1262 ms 8160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 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 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 1276 ms 8420 KB Output is correct
12 Correct 1382 ms 8164 KB Output is correct
13 Correct 1336 ms 7512 KB Output is correct
14 Correct 1285 ms 7312 KB Output is correct
15 Correct 1275 ms 8488 KB Output is correct
16 Correct 1282 ms 7724 KB Output is correct
17 Correct 1298 ms 7760 KB Output is correct
18 Correct 1200 ms 9528 KB Output is correct
19 Correct 1226 ms 6408 KB Output is correct
20 Correct 1262 ms 8160 KB Output is correct
21 Correct 1261 ms 8592 KB Output is correct
22 Correct 1327 ms 8824 KB Output is correct
23 Correct 1496 ms 7872 KB Output is correct
24 Correct 1354 ms 7992 KB Output is correct
25 Correct 1289 ms 9572 KB Output is correct
26 Correct 1424 ms 8060 KB Output is correct
27 Correct 1448 ms 7980 KB Output is correct
28 Correct 1248 ms 10376 KB Output is correct
29 Correct 1297 ms 6592 KB Output is correct
30 Correct 1312 ms 8624 KB Output is correct
31 Correct 1368 ms 8576 KB Output is correct
32 Correct 1378 ms 8512 KB Output is correct
33 Correct 1295 ms 7308 KB Output is correct
34 Correct 1345 ms 7800 KB Output is correct
35 Correct 1342 ms 8108 KB Output is correct
36 Correct 1252 ms 6884 KB Output is correct
37 Correct 1252 ms 8604 KB Output is correct
38 Correct 1235 ms 6688 KB Output is correct
39 Correct 1321 ms 7764 KB Output is correct
40 Correct 1340 ms 7556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 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 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 89 ms 14064 KB Output is correct
12 Correct 94 ms 14160 KB Output is correct
13 Correct 99 ms 14068 KB Output is correct
14 Correct 105 ms 14068 KB Output is correct
15 Correct 93 ms 14064 KB Output is correct
16 Correct 104 ms 14064 KB Output is correct
17 Correct 124 ms 14068 KB Output is correct
18 Correct 91 ms 14292 KB Output is correct
19 Correct 90 ms 13820 KB Output is correct
20 Correct 88 ms 14032 KB Output is correct
21 Correct 93 ms 14016 KB Output is correct
22 Correct 110 ms 13972 KB Output is correct
23 Correct 89 ms 13820 KB Output is correct
24 Correct 99 ms 13928 KB Output is correct
25 Correct 103 ms 14064 KB Output is correct
26 Correct 84 ms 13992 KB Output is correct
27 Correct 89 ms 13944 KB Output is correct
28 Correct 92 ms 14068 KB Output is correct
29 Correct 120 ms 14060 KB Output is correct
30 Correct 111 ms 14068 KB Output is correct
31 Correct 91 ms 13820 KB Output is correct
32 Correct 101 ms 13968 KB Output is correct
33 Correct 129 ms 14260 KB Output is correct
34 Correct 80 ms 13984 KB Output is correct
35 Correct 96 ms 14064 KB Output is correct
36 Correct 112 ms 14436 KB Output is correct
37 Correct 98 ms 14064 KB Output is correct
38 Correct 106 ms 14076 KB Output is correct
39 Correct 111 ms 13992 KB Output is correct
40 Correct 96 ms 14064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 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 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 1276 ms 8420 KB Output is correct
12 Correct 1382 ms 8164 KB Output is correct
13 Correct 1336 ms 7512 KB Output is correct
14 Correct 1285 ms 7312 KB Output is correct
15 Correct 1275 ms 8488 KB Output is correct
16 Correct 1282 ms 7724 KB Output is correct
17 Correct 1298 ms 7760 KB Output is correct
18 Correct 1200 ms 9528 KB Output is correct
19 Correct 1226 ms 6408 KB Output is correct
20 Correct 1262 ms 8160 KB Output is correct
21 Correct 1261 ms 8592 KB Output is correct
22 Correct 1327 ms 8824 KB Output is correct
23 Correct 1496 ms 7872 KB Output is correct
24 Correct 1354 ms 7992 KB Output is correct
25 Correct 1289 ms 9572 KB Output is correct
26 Correct 1424 ms 8060 KB Output is correct
27 Correct 1448 ms 7980 KB Output is correct
28 Correct 1248 ms 10376 KB Output is correct
29 Correct 1297 ms 6592 KB Output is correct
30 Correct 1312 ms 8624 KB Output is correct
31 Correct 1368 ms 8576 KB Output is correct
32 Correct 1378 ms 8512 KB Output is correct
33 Correct 1295 ms 7308 KB Output is correct
34 Correct 1345 ms 7800 KB Output is correct
35 Correct 1342 ms 8108 KB Output is correct
36 Correct 1252 ms 6884 KB Output is correct
37 Correct 1252 ms 8604 KB Output is correct
38 Correct 1235 ms 6688 KB Output is correct
39 Correct 1321 ms 7764 KB Output is correct
40 Correct 1340 ms 7556 KB Output is correct
41 Correct 89 ms 14064 KB Output is correct
42 Correct 94 ms 14160 KB Output is correct
43 Correct 99 ms 14068 KB Output is correct
44 Correct 105 ms 14068 KB Output is correct
45 Correct 93 ms 14064 KB Output is correct
46 Correct 104 ms 14064 KB Output is correct
47 Correct 124 ms 14068 KB Output is correct
48 Correct 91 ms 14292 KB Output is correct
49 Correct 90 ms 13820 KB Output is correct
50 Correct 88 ms 14032 KB Output is correct
51 Correct 93 ms 14016 KB Output is correct
52 Correct 110 ms 13972 KB Output is correct
53 Correct 89 ms 13820 KB Output is correct
54 Correct 99 ms 13928 KB Output is correct
55 Correct 103 ms 14064 KB Output is correct
56 Correct 84 ms 13992 KB Output is correct
57 Correct 89 ms 13944 KB Output is correct
58 Correct 92 ms 14068 KB Output is correct
59 Correct 120 ms 14060 KB Output is correct
60 Correct 111 ms 14068 KB Output is correct
61 Correct 91 ms 13820 KB Output is correct
62 Correct 101 ms 13968 KB Output is correct
63 Correct 129 ms 14260 KB Output is correct
64 Correct 80 ms 13984 KB Output is correct
65 Correct 96 ms 14064 KB Output is correct
66 Correct 112 ms 14436 KB Output is correct
67 Correct 98 ms 14064 KB Output is correct
68 Correct 106 ms 14076 KB Output is correct
69 Correct 111 ms 13992 KB Output is correct
70 Correct 96 ms 14064 KB Output is correct
71 Correct 1469 ms 18924 KB Output is correct
72 Correct 1413 ms 18968 KB Output is correct
73 Correct 1624 ms 17744 KB Output is correct
74 Correct 1656 ms 17852 KB Output is correct
75 Correct 1423 ms 19932 KB Output is correct
76 Correct 1666 ms 18148 KB Output is correct
77 Correct 1733 ms 18088 KB Output is correct
78 Correct 1310 ms 22000 KB Output is correct
79 Correct 1398 ms 15872 KB Output is correct
80 Correct 1394 ms 18992 KB Output is correct
81 Correct 1524 ms 18928 KB Output is correct
82 Correct 1631 ms 17904 KB Output is correct
83 Correct 1448 ms 17160 KB Output is correct
84 Correct 1704 ms 17948 KB Output is correct
85 Correct 1699 ms 18344 KB Output is correct
86 Correct 1307 ms 15752 KB Output is correct
87 Correct 1361 ms 18928 KB Output is correct
88 Correct 1375 ms 16200 KB Output is correct
89 Execution timed out 2037 ms 17896 KB Time limit exceeded
90 Halted 0 ms 0 KB -