답안 #853194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853194 2023-09-23T15:44:03 Z Ahmed57 Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 22024 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
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 4444 KB Output is correct
2 Correct 2 ms 4568 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4444 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 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4568 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4444 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 4444 KB Output is correct
11 Correct 1317 ms 8524 KB Output is correct
12 Correct 1307 ms 8120 KB Output is correct
13 Correct 1322 ms 7512 KB Output is correct
14 Correct 1342 ms 7708 KB Output is correct
15 Correct 1279 ms 8900 KB Output is correct
16 Correct 1285 ms 7676 KB Output is correct
17 Correct 1306 ms 8040 KB Output is correct
18 Correct 1236 ms 9380 KB Output is correct
19 Correct 1268 ms 6708 KB Output is correct
20 Correct 1261 ms 8260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4568 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4444 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 4444 KB Output is correct
11 Correct 1317 ms 8524 KB Output is correct
12 Correct 1307 ms 8120 KB Output is correct
13 Correct 1322 ms 7512 KB Output is correct
14 Correct 1342 ms 7708 KB Output is correct
15 Correct 1279 ms 8900 KB Output is correct
16 Correct 1285 ms 7676 KB Output is correct
17 Correct 1306 ms 8040 KB Output is correct
18 Correct 1236 ms 9380 KB Output is correct
19 Correct 1268 ms 6708 KB Output is correct
20 Correct 1261 ms 8260 KB Output is correct
21 Correct 1296 ms 8552 KB Output is correct
22 Correct 1350 ms 8756 KB Output is correct
23 Correct 1437 ms 7552 KB Output is correct
24 Correct 1335 ms 7512 KB Output is correct
25 Correct 1308 ms 9668 KB Output is correct
26 Correct 1329 ms 8292 KB Output is correct
27 Correct 1341 ms 8004 KB Output is correct
28 Correct 1240 ms 10896 KB Output is correct
29 Correct 1384 ms 7012 KB Output is correct
30 Correct 1306 ms 8868 KB Output is correct
31 Correct 1314 ms 8820 KB Output is correct
32 Correct 1331 ms 8576 KB Output is correct
33 Correct 1341 ms 7716 KB Output is correct
34 Correct 1342 ms 7376 KB Output is correct
35 Correct 1341 ms 8108 KB Output is correct
36 Correct 1250 ms 6884 KB Output is correct
37 Correct 1310 ms 8652 KB Output is correct
38 Correct 1285 ms 6520 KB Output is correct
39 Correct 1403 ms 7840 KB Output is correct
40 Correct 1337 ms 7560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4568 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4444 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 4444 KB Output is correct
11 Correct 98 ms 14016 KB Output is correct
12 Correct 101 ms 14308 KB Output is correct
13 Correct 98 ms 13940 KB Output is correct
14 Correct 100 ms 14068 KB Output is correct
15 Correct 92 ms 14196 KB Output is correct
16 Correct 127 ms 14064 KB Output is correct
17 Correct 101 ms 13944 KB Output is correct
18 Correct 88 ms 14244 KB Output is correct
19 Correct 115 ms 13824 KB Output is correct
20 Correct 97 ms 14120 KB Output is correct
21 Correct 114 ms 13920 KB Output is correct
22 Correct 100 ms 13920 KB Output is correct
23 Correct 93 ms 14068 KB Output is correct
24 Correct 100 ms 13976 KB Output is correct
25 Correct 119 ms 14196 KB Output is correct
26 Correct 100 ms 14228 KB Output is correct
27 Correct 93 ms 14120 KB Output is correct
28 Correct 100 ms 14204 KB Output is correct
29 Correct 113 ms 13968 KB Output is correct
30 Correct 106 ms 14072 KB Output is correct
31 Correct 106 ms 13952 KB Output is correct
32 Correct 104 ms 14064 KB Output is correct
33 Correct 120 ms 14420 KB Output is correct
34 Correct 104 ms 14204 KB Output is correct
35 Correct 99 ms 13936 KB Output is correct
36 Correct 98 ms 14264 KB Output is correct
37 Correct 99 ms 13996 KB Output is correct
38 Correct 114 ms 14080 KB Output is correct
39 Correct 123 ms 14032 KB Output is correct
40 Correct 97 ms 14064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4568 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4444 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 4444 KB Output is correct
11 Correct 1317 ms 8524 KB Output is correct
12 Correct 1307 ms 8120 KB Output is correct
13 Correct 1322 ms 7512 KB Output is correct
14 Correct 1342 ms 7708 KB Output is correct
15 Correct 1279 ms 8900 KB Output is correct
16 Correct 1285 ms 7676 KB Output is correct
17 Correct 1306 ms 8040 KB Output is correct
18 Correct 1236 ms 9380 KB Output is correct
19 Correct 1268 ms 6708 KB Output is correct
20 Correct 1261 ms 8260 KB Output is correct
21 Correct 1296 ms 8552 KB Output is correct
22 Correct 1350 ms 8756 KB Output is correct
23 Correct 1437 ms 7552 KB Output is correct
24 Correct 1335 ms 7512 KB Output is correct
25 Correct 1308 ms 9668 KB Output is correct
26 Correct 1329 ms 8292 KB Output is correct
27 Correct 1341 ms 8004 KB Output is correct
28 Correct 1240 ms 10896 KB Output is correct
29 Correct 1384 ms 7012 KB Output is correct
30 Correct 1306 ms 8868 KB Output is correct
31 Correct 1314 ms 8820 KB Output is correct
32 Correct 1331 ms 8576 KB Output is correct
33 Correct 1341 ms 7716 KB Output is correct
34 Correct 1342 ms 7376 KB Output is correct
35 Correct 1341 ms 8108 KB Output is correct
36 Correct 1250 ms 6884 KB Output is correct
37 Correct 1310 ms 8652 KB Output is correct
38 Correct 1285 ms 6520 KB Output is correct
39 Correct 1403 ms 7840 KB Output is correct
40 Correct 1337 ms 7560 KB Output is correct
41 Correct 98 ms 14016 KB Output is correct
42 Correct 101 ms 14308 KB Output is correct
43 Correct 98 ms 13940 KB Output is correct
44 Correct 100 ms 14068 KB Output is correct
45 Correct 92 ms 14196 KB Output is correct
46 Correct 127 ms 14064 KB Output is correct
47 Correct 101 ms 13944 KB Output is correct
48 Correct 88 ms 14244 KB Output is correct
49 Correct 115 ms 13824 KB Output is correct
50 Correct 97 ms 14120 KB Output is correct
51 Correct 114 ms 13920 KB Output is correct
52 Correct 100 ms 13920 KB Output is correct
53 Correct 93 ms 14068 KB Output is correct
54 Correct 100 ms 13976 KB Output is correct
55 Correct 119 ms 14196 KB Output is correct
56 Correct 100 ms 14228 KB Output is correct
57 Correct 93 ms 14120 KB Output is correct
58 Correct 100 ms 14204 KB Output is correct
59 Correct 113 ms 13968 KB Output is correct
60 Correct 106 ms 14072 KB Output is correct
61 Correct 106 ms 13952 KB Output is correct
62 Correct 104 ms 14064 KB Output is correct
63 Correct 120 ms 14420 KB Output is correct
64 Correct 104 ms 14204 KB Output is correct
65 Correct 99 ms 13936 KB Output is correct
66 Correct 98 ms 14264 KB Output is correct
67 Correct 99 ms 13996 KB Output is correct
68 Correct 114 ms 14080 KB Output is correct
69 Correct 123 ms 14032 KB Output is correct
70 Correct 97 ms 14064 KB Output is correct
71 Correct 1452 ms 18780 KB Output is correct
72 Correct 1518 ms 19188 KB Output is correct
73 Correct 1652 ms 17588 KB Output is correct
74 Correct 1617 ms 18044 KB Output is correct
75 Correct 1486 ms 19784 KB Output is correct
76 Correct 1606 ms 18244 KB Output is correct
77 Correct 1709 ms 18136 KB Output is correct
78 Correct 1373 ms 22024 KB Output is correct
79 Correct 1421 ms 15752 KB Output is correct
80 Correct 1486 ms 19044 KB Output is correct
81 Correct 1482 ms 19364 KB Output is correct
82 Correct 1592 ms 18236 KB Output is correct
83 Correct 1474 ms 16940 KB Output is correct
84 Correct 1618 ms 17800 KB Output is correct
85 Correct 1746 ms 18160 KB Output is correct
86 Correct 1348 ms 15972 KB Output is correct
87 Correct 1458 ms 18916 KB Output is correct
88 Correct 1582 ms 16096 KB Output is correct
89 Execution timed out 2037 ms 17640 KB Time limit exceeded
90 Halted 0 ms 0 KB -