답안 #848582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
848582 2023-09-13T01:01:27 Z vjudge1 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
797 ms 54936 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define pii pair<int,int>
const int inf=1e18;
const int mod=998244353;
const int maxn=100005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
int n,q,f1[(1<<20)+5],f2[(1<<20)+5],a[(1<<20)+5];
void solve(){
    cin >> n >> q;
    for(int i=0;i<(1<<n);i++){
        char c;cin >> c;
        f1[i]=f2[i]=a[i]=c-'0';
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<n);j++){
            if(j&(1<<i)) f1[j]+=f1[j^(1<<i)];
            else f2[j]+=f2[j^(1<<i)];
        }
    }
    for(int _=1;_<=q;_++){
        string s;cin >> s;
        int num=0,m0=0,m1=0,m2=0,cnt0=0,cnt1=0,cnt2=0;
        for(int i=0;i<n;i++){
            if(s[i]!='?'){
                num=num*2+(s[i]-'0');
                if(s[i]=='0'){cnt0++;m0+=(1<<(n-i-1));}
                else{cnt1++;;m1+=(1<<(n-i-1));}
            }
            else{num=num*2+1;m2+=(1<<(n-i-1));cnt2++;}
        }
        int res=0;
        if(cnt0<=cnt1 && cnt0<=cnt2){
            num^=m2;
            for(int i=m0;;i=(i-1)&m0){
                if(__builtin_popcount(i)&1) res-=f2[num^i];
                else res+=f2[num^i];
                if(i==0) break;
            }
        }
        else if(cnt1<=cnt0 && cnt1<=cnt2){
            for(int i=m1;;i=(i-1)&m1){
                if(__builtin_popcount(i)&1) res-=f1[num^i];
                else res+=f1[num^i];
                if(i==0) break;
            }
        }
        else{
            for(int i=m2;;i=(i-1)&m2){
                res+=a[num^i];
                if(i==0) break;
            }
        }
        cout << res << '\n';
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t=1;//cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 163 ms 19148 KB Output is correct
12 Correct 169 ms 18872 KB Output is correct
13 Correct 184 ms 18192 KB Output is correct
14 Correct 202 ms 18116 KB Output is correct
15 Correct 187 ms 19280 KB Output is correct
16 Correct 207 ms 18760 KB Output is correct
17 Correct 206 ms 18340 KB Output is correct
18 Correct 134 ms 20304 KB Output is correct
19 Correct 161 ms 17388 KB Output is correct
20 Correct 170 ms 18768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 163 ms 19148 KB Output is correct
12 Correct 169 ms 18872 KB Output is correct
13 Correct 184 ms 18192 KB Output is correct
14 Correct 202 ms 18116 KB Output is correct
15 Correct 187 ms 19280 KB Output is correct
16 Correct 207 ms 18760 KB Output is correct
17 Correct 206 ms 18340 KB Output is correct
18 Correct 134 ms 20304 KB Output is correct
19 Correct 161 ms 17388 KB Output is correct
20 Correct 170 ms 18768 KB Output is correct
21 Correct 181 ms 22096 KB Output is correct
22 Correct 195 ms 22612 KB Output is correct
23 Correct 216 ms 21328 KB Output is correct
24 Correct 259 ms 21244 KB Output is correct
25 Correct 215 ms 23268 KB Output is correct
26 Correct 264 ms 21696 KB Output is correct
27 Correct 236 ms 21584 KB Output is correct
28 Correct 177 ms 24144 KB Output is correct
29 Correct 181 ms 20304 KB Output is correct
30 Correct 201 ms 22352 KB Output is correct
31 Correct 232 ms 22096 KB Output is correct
32 Correct 256 ms 22132 KB Output is correct
33 Correct 191 ms 21072 KB Output is correct
34 Correct 241 ms 21328 KB Output is correct
35 Correct 244 ms 21952 KB Output is correct
36 Correct 140 ms 20216 KB Output is correct
37 Correct 182 ms 22100 KB Output is correct
38 Correct 195 ms 20256 KB Output is correct
39 Correct 213 ms 21328 KB Output is correct
40 Correct 260 ms 21124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 44 ms 27216 KB Output is correct
12 Correct 49 ms 27216 KB Output is correct
13 Correct 49 ms 27216 KB Output is correct
14 Correct 61 ms 27264 KB Output is correct
15 Correct 51 ms 27412 KB Output is correct
16 Correct 64 ms 27216 KB Output is correct
17 Correct 65 ms 27220 KB Output is correct
18 Correct 40 ms 27476 KB Output is correct
19 Correct 46 ms 27216 KB Output is correct
20 Correct 60 ms 27472 KB Output is correct
21 Correct 50 ms 27216 KB Output is correct
22 Correct 57 ms 27108 KB Output is correct
23 Correct 46 ms 27216 KB Output is correct
24 Correct 77 ms 27224 KB Output is correct
25 Correct 64 ms 27104 KB Output is correct
26 Correct 41 ms 27216 KB Output is correct
27 Correct 49 ms 27216 KB Output is correct
28 Correct 45 ms 27100 KB Output is correct
29 Correct 54 ms 27104 KB Output is correct
30 Correct 62 ms 27288 KB Output is correct
31 Correct 48 ms 27216 KB Output is correct
32 Correct 66 ms 27216 KB Output is correct
33 Correct 62 ms 27220 KB Output is correct
34 Correct 40 ms 27216 KB Output is correct
35 Correct 59 ms 27368 KB Output is correct
36 Correct 75 ms 27212 KB Output is correct
37 Correct 57 ms 27216 KB Output is correct
38 Correct 57 ms 27216 KB Output is correct
39 Correct 57 ms 27220 KB Output is correct
40 Correct 59 ms 27216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 163 ms 19148 KB Output is correct
12 Correct 169 ms 18872 KB Output is correct
13 Correct 184 ms 18192 KB Output is correct
14 Correct 202 ms 18116 KB Output is correct
15 Correct 187 ms 19280 KB Output is correct
16 Correct 207 ms 18760 KB Output is correct
17 Correct 206 ms 18340 KB Output is correct
18 Correct 134 ms 20304 KB Output is correct
19 Correct 161 ms 17388 KB Output is correct
20 Correct 170 ms 18768 KB Output is correct
21 Correct 181 ms 22096 KB Output is correct
22 Correct 195 ms 22612 KB Output is correct
23 Correct 216 ms 21328 KB Output is correct
24 Correct 259 ms 21244 KB Output is correct
25 Correct 215 ms 23268 KB Output is correct
26 Correct 264 ms 21696 KB Output is correct
27 Correct 236 ms 21584 KB Output is correct
28 Correct 177 ms 24144 KB Output is correct
29 Correct 181 ms 20304 KB Output is correct
30 Correct 201 ms 22352 KB Output is correct
31 Correct 232 ms 22096 KB Output is correct
32 Correct 256 ms 22132 KB Output is correct
33 Correct 191 ms 21072 KB Output is correct
34 Correct 241 ms 21328 KB Output is correct
35 Correct 244 ms 21952 KB Output is correct
36 Correct 140 ms 20216 KB Output is correct
37 Correct 182 ms 22100 KB Output is correct
38 Correct 195 ms 20256 KB Output is correct
39 Correct 213 ms 21328 KB Output is correct
40 Correct 260 ms 21124 KB Output is correct
41 Correct 44 ms 27216 KB Output is correct
42 Correct 49 ms 27216 KB Output is correct
43 Correct 49 ms 27216 KB Output is correct
44 Correct 61 ms 27264 KB Output is correct
45 Correct 51 ms 27412 KB Output is correct
46 Correct 64 ms 27216 KB Output is correct
47 Correct 65 ms 27220 KB Output is correct
48 Correct 40 ms 27476 KB Output is correct
49 Correct 46 ms 27216 KB Output is correct
50 Correct 60 ms 27472 KB Output is correct
51 Correct 50 ms 27216 KB Output is correct
52 Correct 57 ms 27108 KB Output is correct
53 Correct 46 ms 27216 KB Output is correct
54 Correct 77 ms 27224 KB Output is correct
55 Correct 64 ms 27104 KB Output is correct
56 Correct 41 ms 27216 KB Output is correct
57 Correct 49 ms 27216 KB Output is correct
58 Correct 45 ms 27100 KB Output is correct
59 Correct 54 ms 27104 KB Output is correct
60 Correct 62 ms 27288 KB Output is correct
61 Correct 48 ms 27216 KB Output is correct
62 Correct 66 ms 27216 KB Output is correct
63 Correct 62 ms 27220 KB Output is correct
64 Correct 40 ms 27216 KB Output is correct
65 Correct 59 ms 27368 KB Output is correct
66 Correct 75 ms 27212 KB Output is correct
67 Correct 57 ms 27216 KB Output is correct
68 Correct 57 ms 27216 KB Output is correct
69 Correct 57 ms 27220 KB Output is correct
70 Correct 59 ms 27216 KB Output is correct
71 Correct 342 ms 51636 KB Output is correct
72 Correct 316 ms 51796 KB Output is correct
73 Correct 400 ms 50244 KB Output is correct
74 Correct 572 ms 50420 KB Output is correct
75 Correct 341 ms 52560 KB Output is correct
76 Correct 700 ms 51120 KB Output is correct
77 Correct 707 ms 51280 KB Output is correct
78 Correct 223 ms 54936 KB Output is correct
79 Correct 319 ms 48856 KB Output is correct
80 Correct 307 ms 51792 KB Output is correct
81 Correct 414 ms 51536 KB Output is correct
82 Correct 560 ms 50500 KB Output is correct
83 Correct 365 ms 49744 KB Output is correct
84 Correct 790 ms 50512 KB Output is correct
85 Correct 787 ms 50624 KB Output is correct
86 Correct 254 ms 48580 KB Output is correct
87 Correct 317 ms 51500 KB Output is correct
88 Correct 341 ms 48208 KB Output is correct
89 Correct 440 ms 50256 KB Output is correct
90 Correct 420 ms 50584 KB Output is correct
91 Correct 313 ms 49796 KB Output is correct
92 Correct 797 ms 50876 KB Output is correct
93 Correct 714 ms 51024 KB Output is correct
94 Correct 227 ms 48464 KB Output is correct
95 Correct 632 ms 50684 KB Output is correct
96 Correct 599 ms 50628 KB Output is correct
97 Correct 635 ms 50768 KB Output is correct
98 Correct 631 ms 50768 KB Output is correct
99 Correct 608 ms 50892 KB Output is correct
100 Correct 655 ms 50512 KB Output is correct