답안 #678633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678633 2023-01-06T09:03:47 Z vjudge1 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1057 ms 34508 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 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 189 ms 11620 KB Output is correct
12 Correct 240 ms 11280 KB Output is correct
13 Correct 202 ms 10484 KB Output is correct
14 Correct 257 ms 10632 KB Output is correct
15 Correct 213 ms 11604 KB Output is correct
16 Correct 235 ms 10780 KB Output is correct
17 Correct 229 ms 10668 KB Output is correct
18 Correct 163 ms 12620 KB Output is correct
19 Correct 178 ms 9548 KB Output is correct
20 Correct 202 ms 11176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 189 ms 11620 KB Output is correct
12 Correct 240 ms 11280 KB Output is correct
13 Correct 202 ms 10484 KB Output is correct
14 Correct 257 ms 10632 KB Output is correct
15 Correct 213 ms 11604 KB Output is correct
16 Correct 235 ms 10780 KB Output is correct
17 Correct 229 ms 10668 KB Output is correct
18 Correct 163 ms 12620 KB Output is correct
19 Correct 178 ms 9548 KB Output is correct
20 Correct 202 ms 11176 KB Output is correct
21 Correct 218 ms 11776 KB Output is correct
22 Correct 227 ms 11928 KB Output is correct
23 Correct 253 ms 10864 KB Output is correct
24 Correct 283 ms 10516 KB Output is correct
25 Correct 242 ms 12104 KB Output is correct
26 Correct 285 ms 10348 KB Output is correct
27 Correct 278 ms 10208 KB Output is correct
28 Correct 162 ms 12364 KB Output is correct
29 Correct 217 ms 8232 KB Output is correct
30 Correct 213 ms 9824 KB Output is correct
31 Correct 301 ms 9564 KB Output is correct
32 Correct 284 ms 9420 KB Output is correct
33 Correct 249 ms 8024 KB Output is correct
34 Correct 291 ms 8012 KB Output is correct
35 Correct 302 ms 8164 KB Output is correct
36 Correct 187 ms 6540 KB Output is correct
37 Correct 202 ms 8272 KB Output is correct
38 Correct 220 ms 6052 KB Output is correct
39 Correct 247 ms 6848 KB Output is correct
40 Correct 285 ms 6448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 68 ms 27112 KB Output is correct
12 Correct 68 ms 27172 KB Output is correct
13 Correct 106 ms 27084 KB Output is correct
14 Correct 96 ms 27216 KB Output is correct
15 Correct 79 ms 27172 KB Output is correct
16 Correct 103 ms 27112 KB Output is correct
17 Correct 91 ms 27088 KB Output is correct
18 Correct 63 ms 27312 KB Output is correct
19 Correct 69 ms 27184 KB Output is correct
20 Correct 70 ms 27164 KB Output is correct
21 Correct 92 ms 27132 KB Output is correct
22 Correct 100 ms 27076 KB Output is correct
23 Correct 82 ms 27040 KB Output is correct
24 Correct 116 ms 27140 KB Output is correct
25 Correct 97 ms 27140 KB Output is correct
26 Correct 66 ms 26956 KB Output is correct
27 Correct 67 ms 27128 KB Output is correct
28 Correct 73 ms 27044 KB Output is correct
29 Correct 87 ms 27084 KB Output is correct
30 Correct 95 ms 27084 KB Output is correct
31 Correct 70 ms 26912 KB Output is correct
32 Correct 133 ms 27072 KB Output is correct
33 Correct 95 ms 26972 KB Output is correct
34 Correct 65 ms 26932 KB Output is correct
35 Correct 93 ms 26880 KB Output is correct
36 Correct 82 ms 26828 KB Output is correct
37 Correct 102 ms 26740 KB Output is correct
38 Correct 100 ms 26928 KB Output is correct
39 Correct 98 ms 26556 KB Output is correct
40 Correct 105 ms 26596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 189 ms 11620 KB Output is correct
12 Correct 240 ms 11280 KB Output is correct
13 Correct 202 ms 10484 KB Output is correct
14 Correct 257 ms 10632 KB Output is correct
15 Correct 213 ms 11604 KB Output is correct
16 Correct 235 ms 10780 KB Output is correct
17 Correct 229 ms 10668 KB Output is correct
18 Correct 163 ms 12620 KB Output is correct
19 Correct 178 ms 9548 KB Output is correct
20 Correct 202 ms 11176 KB Output is correct
21 Correct 218 ms 11776 KB Output is correct
22 Correct 227 ms 11928 KB Output is correct
23 Correct 253 ms 10864 KB Output is correct
24 Correct 283 ms 10516 KB Output is correct
25 Correct 242 ms 12104 KB Output is correct
26 Correct 285 ms 10348 KB Output is correct
27 Correct 278 ms 10208 KB Output is correct
28 Correct 162 ms 12364 KB Output is correct
29 Correct 217 ms 8232 KB Output is correct
30 Correct 213 ms 9824 KB Output is correct
31 Correct 301 ms 9564 KB Output is correct
32 Correct 284 ms 9420 KB Output is correct
33 Correct 249 ms 8024 KB Output is correct
34 Correct 291 ms 8012 KB Output is correct
35 Correct 302 ms 8164 KB Output is correct
36 Correct 187 ms 6540 KB Output is correct
37 Correct 202 ms 8272 KB Output is correct
38 Correct 220 ms 6052 KB Output is correct
39 Correct 247 ms 6848 KB Output is correct
40 Correct 285 ms 6448 KB Output is correct
41 Correct 68 ms 27112 KB Output is correct
42 Correct 68 ms 27172 KB Output is correct
43 Correct 106 ms 27084 KB Output is correct
44 Correct 96 ms 27216 KB Output is correct
45 Correct 79 ms 27172 KB Output is correct
46 Correct 103 ms 27112 KB Output is correct
47 Correct 91 ms 27088 KB Output is correct
48 Correct 63 ms 27312 KB Output is correct
49 Correct 69 ms 27184 KB Output is correct
50 Correct 70 ms 27164 KB Output is correct
51 Correct 92 ms 27132 KB Output is correct
52 Correct 100 ms 27076 KB Output is correct
53 Correct 82 ms 27040 KB Output is correct
54 Correct 116 ms 27140 KB Output is correct
55 Correct 97 ms 27140 KB Output is correct
56 Correct 66 ms 26956 KB Output is correct
57 Correct 67 ms 27128 KB Output is correct
58 Correct 73 ms 27044 KB Output is correct
59 Correct 87 ms 27084 KB Output is correct
60 Correct 95 ms 27084 KB Output is correct
61 Correct 70 ms 26912 KB Output is correct
62 Correct 133 ms 27072 KB Output is correct
63 Correct 95 ms 26972 KB Output is correct
64 Correct 65 ms 26932 KB Output is correct
65 Correct 93 ms 26880 KB Output is correct
66 Correct 82 ms 26828 KB Output is correct
67 Correct 102 ms 26740 KB Output is correct
68 Correct 100 ms 26928 KB Output is correct
69 Correct 98 ms 26556 KB Output is correct
70 Correct 105 ms 26596 KB Output is correct
71 Correct 398 ms 31440 KB Output is correct
72 Correct 418 ms 31800 KB Output is correct
73 Correct 540 ms 30096 KB Output is correct
74 Correct 901 ms 30368 KB Output is correct
75 Correct 415 ms 32468 KB Output is correct
76 Correct 1010 ms 30852 KB Output is correct
77 Correct 905 ms 30676 KB Output is correct
78 Correct 262 ms 34508 KB Output is correct
79 Correct 354 ms 28356 KB Output is correct
80 Correct 384 ms 31404 KB Output is correct
81 Correct 600 ms 31256 KB Output is correct
82 Correct 1057 ms 30324 KB Output is correct
83 Correct 421 ms 29320 KB Output is correct
84 Correct 1053 ms 30168 KB Output is correct
85 Correct 808 ms 30212 KB Output is correct
86 Correct 246 ms 27988 KB Output is correct
87 Correct 361 ms 31016 KB Output is correct
88 Correct 419 ms 27796 KB Output is correct
89 Correct 631 ms 29532 KB Output is correct
90 Correct 706 ms 29832 KB Output is correct
91 Correct 367 ms 28856 KB Output is correct
92 Correct 1008 ms 29960 KB Output is correct
93 Correct 792 ms 29844 KB Output is correct
94 Correct 256 ms 27596 KB Output is correct
95 Correct 656 ms 29740 KB Output is correct
96 Correct 687 ms 29564 KB Output is correct
97 Correct 664 ms 29516 KB Output is correct
98 Correct 743 ms 29436 KB Output is correct
99 Correct 670 ms 29328 KB Output is correct
100 Correct 658 ms 29404 KB Output is correct