답안 #853184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853184 2023-09-23T15:36:24 Z Ahmed57 Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 43760 KB
#include <bits/stdc++.h>
using namespace std;
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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4440 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 4440 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4440 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 4440 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1234 ms 9140 KB Output is correct
12 Correct 1297 ms 8308 KB Output is correct
13 Correct 1325 ms 7460 KB Output is correct
14 Correct 1289 ms 7508 KB Output is correct
15 Correct 1249 ms 8424 KB Output is correct
16 Correct 1275 ms 8008 KB Output is correct
17 Correct 1320 ms 7544 KB Output is correct
18 Correct 1204 ms 9684 KB Output is correct
19 Correct 1226 ms 6624 KB Output is correct
20 Correct 1240 ms 8388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4440 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 4440 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1234 ms 9140 KB Output is correct
12 Correct 1297 ms 8308 KB Output is correct
13 Correct 1325 ms 7460 KB Output is correct
14 Correct 1289 ms 7508 KB Output is correct
15 Correct 1249 ms 8424 KB Output is correct
16 Correct 1275 ms 8008 KB Output is correct
17 Correct 1320 ms 7544 KB Output is correct
18 Correct 1204 ms 9684 KB Output is correct
19 Correct 1226 ms 6624 KB Output is correct
20 Correct 1240 ms 8388 KB Output is correct
21 Correct 1248 ms 8844 KB Output is correct
22 Correct 1305 ms 8656 KB Output is correct
23 Correct 1466 ms 7840 KB Output is correct
24 Correct 1359 ms 7520 KB Output is correct
25 Correct 1291 ms 9464 KB Output is correct
26 Correct 1340 ms 8248 KB Output is correct
27 Correct 1340 ms 7980 KB Output is correct
28 Correct 1225 ms 10612 KB Output is correct
29 Correct 1257 ms 6488 KB Output is correct
30 Correct 1252 ms 8828 KB Output is correct
31 Correct 1345 ms 8592 KB Output is correct
32 Correct 1347 ms 8532 KB Output is correct
33 Correct 1281 ms 7432 KB Output is correct
34 Correct 1333 ms 7396 KB Output is correct
35 Correct 1342 ms 7828 KB Output is correct
36 Correct 1220 ms 6352 KB Output is correct
37 Correct 1251 ms 8584 KB Output is correct
38 Correct 1242 ms 6480 KB Output is correct
39 Correct 1314 ms 7740 KB Output is correct
40 Correct 1349 ms 7560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4440 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 4440 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 90 ms 14064 KB Output is correct
12 Correct 90 ms 14064 KB Output is correct
13 Correct 103 ms 14320 KB Output is correct
14 Correct 102 ms 13988 KB Output is correct
15 Correct 91 ms 14064 KB Output is correct
16 Correct 102 ms 13976 KB Output is correct
17 Correct 105 ms 14060 KB Output is correct
18 Correct 86 ms 14296 KB Output is correct
19 Correct 90 ms 13984 KB Output is correct
20 Correct 96 ms 13980 KB Output is correct
21 Correct 95 ms 14064 KB Output is correct
22 Correct 108 ms 13960 KB Output is correct
23 Correct 90 ms 13820 KB Output is correct
24 Correct 103 ms 13928 KB Output is correct
25 Correct 121 ms 13928 KB Output is correct
26 Correct 85 ms 13820 KB Output is correct
27 Correct 94 ms 14428 KB Output is correct
28 Correct 89 ms 13820 KB Output is correct
29 Correct 126 ms 14064 KB Output is correct
30 Correct 117 ms 14092 KB Output is correct
31 Correct 92 ms 14064 KB Output is correct
32 Correct 101 ms 14064 KB Output is correct
33 Correct 116 ms 14064 KB Output is correct
34 Correct 85 ms 13820 KB Output is correct
35 Correct 99 ms 13920 KB Output is correct
36 Correct 110 ms 14064 KB Output is correct
37 Correct 119 ms 14064 KB Output is correct
38 Correct 97 ms 14048 KB Output is correct
39 Correct 109 ms 14064 KB Output is correct
40 Correct 100 ms 14064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4440 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 4440 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1234 ms 9140 KB Output is correct
12 Correct 1297 ms 8308 KB Output is correct
13 Correct 1325 ms 7460 KB Output is correct
14 Correct 1289 ms 7508 KB Output is correct
15 Correct 1249 ms 8424 KB Output is correct
16 Correct 1275 ms 8008 KB Output is correct
17 Correct 1320 ms 7544 KB Output is correct
18 Correct 1204 ms 9684 KB Output is correct
19 Correct 1226 ms 6624 KB Output is correct
20 Correct 1240 ms 8388 KB Output is correct
21 Correct 1248 ms 8844 KB Output is correct
22 Correct 1305 ms 8656 KB Output is correct
23 Correct 1466 ms 7840 KB Output is correct
24 Correct 1359 ms 7520 KB Output is correct
25 Correct 1291 ms 9464 KB Output is correct
26 Correct 1340 ms 8248 KB Output is correct
27 Correct 1340 ms 7980 KB Output is correct
28 Correct 1225 ms 10612 KB Output is correct
29 Correct 1257 ms 6488 KB Output is correct
30 Correct 1252 ms 8828 KB Output is correct
31 Correct 1345 ms 8592 KB Output is correct
32 Correct 1347 ms 8532 KB Output is correct
33 Correct 1281 ms 7432 KB Output is correct
34 Correct 1333 ms 7396 KB Output is correct
35 Correct 1342 ms 7828 KB Output is correct
36 Correct 1220 ms 6352 KB Output is correct
37 Correct 1251 ms 8584 KB Output is correct
38 Correct 1242 ms 6480 KB Output is correct
39 Correct 1314 ms 7740 KB Output is correct
40 Correct 1349 ms 7560 KB Output is correct
41 Correct 90 ms 14064 KB Output is correct
42 Correct 90 ms 14064 KB Output is correct
43 Correct 103 ms 14320 KB Output is correct
44 Correct 102 ms 13988 KB Output is correct
45 Correct 91 ms 14064 KB Output is correct
46 Correct 102 ms 13976 KB Output is correct
47 Correct 105 ms 14060 KB Output is correct
48 Correct 86 ms 14296 KB Output is correct
49 Correct 90 ms 13984 KB Output is correct
50 Correct 96 ms 13980 KB Output is correct
51 Correct 95 ms 14064 KB Output is correct
52 Correct 108 ms 13960 KB Output is correct
53 Correct 90 ms 13820 KB Output is correct
54 Correct 103 ms 13928 KB Output is correct
55 Correct 121 ms 13928 KB Output is correct
56 Correct 85 ms 13820 KB Output is correct
57 Correct 94 ms 14428 KB Output is correct
58 Correct 89 ms 13820 KB Output is correct
59 Correct 126 ms 14064 KB Output is correct
60 Correct 117 ms 14092 KB Output is correct
61 Correct 92 ms 14064 KB Output is correct
62 Correct 101 ms 14064 KB Output is correct
63 Correct 116 ms 14064 KB Output is correct
64 Correct 85 ms 13820 KB Output is correct
65 Correct 99 ms 13920 KB Output is correct
66 Correct 110 ms 14064 KB Output is correct
67 Correct 119 ms 14064 KB Output is correct
68 Correct 97 ms 14048 KB Output is correct
69 Correct 109 ms 14064 KB Output is correct
70 Correct 100 ms 14064 KB Output is correct
71 Correct 1425 ms 18928 KB Output is correct
72 Correct 1422 ms 19184 KB Output is correct
73 Correct 1605 ms 17480 KB Output is correct
74 Correct 1641 ms 18940 KB Output is correct
75 Correct 1440 ms 41696 KB Output is correct
76 Correct 1652 ms 40008 KB Output is correct
77 Correct 1851 ms 39812 KB Output is correct
78 Correct 1300 ms 43760 KB Output is correct
79 Correct 1419 ms 37756 KB Output is correct
80 Correct 1415 ms 40500 KB Output is correct
81 Correct 1508 ms 40700 KB Output is correct
82 Correct 1669 ms 39740 KB Output is correct
83 Correct 1432 ms 38680 KB Output is correct
84 Correct 1709 ms 39704 KB Output is correct
85 Correct 1749 ms 39700 KB Output is correct
86 Correct 1291 ms 37360 KB Output is correct
87 Correct 1437 ms 40596 KB Output is correct
88 Correct 1413 ms 37456 KB Output is correct
89 Execution timed out 2008 ms 38368 KB Time limit exceeded
90 Halted 0 ms 0 KB -