Submission #1014565

# Submission time Handle Problem Language Result Execution time Memory
1014565 2024-07-05T07:10:02 Z boyliguanhan Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1060 ms 43336 KB
#include<bits/stdc++.h>
using namespace std;
int dp1[1<<20],dp2[1<<20],orig[1<<20];
void readst(string &str){
    char c=getchar();
    while(c==' '||c=='\n')
        c=getchar();
    while(c!=' '&&c!='\n')
        str+=c,c=getchar();
}
void brute(string a){
    vector<int>can;
    int k=0,l=a.size()-1,ans=0;
    for(int i=0;i<=l;i++)
        if(a[i]=='?') k<<=1,
            can.push_back(l-i);
        else k<<=1,k+=a[i]-48;
    int x=can.size();
    for(int i=0;i<1<<x;i++){
        int k2=k;
        for(int j=0;j<x;j++)
            k2|=(i>>j&1)<<can[j];
        ans+=orig[k2];
    }
    cout<<ans<<'\n';
}
void subs(string a){
    vector<int>can;
    int k=0,l=a.size()-1,ans=0;
    for(int i=0;i<=l;i++)
        if(a[i]=='?') k=k<<1|1;
        else if(a[i]=='0') k<<=1;
        else can.push_back(l-i),k=k<<1|1;
    int x=can.size();
    for(int i=0;i<1<<x;i++){
        int k2=k;
        for(int j=0;j<x;j++)
            k2^=(i>>j&1)<<can[j];
        int y=__builtin_popcount(i)%2;
        ans+=(-y*2+1)*dp1[k2];
    }
    cout<<ans<<'\n';
}
void sups(string a){
    vector<int>can;
    int k=0,l=a.size()-1,ans=0;
    for(int i=0;i<=l;i++)
        if(a[i]=='?') k<<=1;
        else if(a[i]=='1')k=k<<1|1;
        else can.push_back(l-i),k<<=1;
    int x=can.size();
    for(int i=0;i<1<<x;i++){
        int k2=k;
        for(int j=0;j<x;j++)
            k2^=(i>>j&1)<<can[j];
        int y=__builtin_popcount(i)%2;
        ans+=(-y*2+1)*dp2[k2];
    }
    cout<<ans<<'\n';
}
int main(){
    int n,m;
    string str;
    cin>>n>>m;
    readst(str);
    for(int i=0;i<1<<n;i++)
        dp1[i]=dp2[i]=orig[i]=str[i]-48;
    for(int i=0;i<n;i++) for(int j=0;j<1<<n;j++)
        if(j&1<<i) dp1[j]+=dp1[j^1<<i],dp2[j^1<<i]+=dp2[j];
    while(m--){
        string qr;
        readst(qr);
        int a=0,b=0,c=0;
        for(auto i:qr)
            if(i=='0')
                a++;
            else if(i=='1')
                b++;
            else c++;
        if(c<=6)brute(qr);
        else if(b<=6)subs(qr);
        else sups(qr);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 346 ms 15188 KB Output is correct
12 Correct 332 ms 14672 KB Output is correct
13 Correct 254 ms 13908 KB Output is correct
14 Correct 257 ms 14176 KB Output is correct
15 Correct 538 ms 15268 KB Output is correct
16 Correct 325 ms 14164 KB Output is correct
17 Correct 316 ms 14216 KB Output is correct
18 Correct 114 ms 16192 KB Output is correct
19 Correct 138 ms 12968 KB Output is correct
20 Correct 356 ms 14728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 346 ms 15188 KB Output is correct
12 Correct 332 ms 14672 KB Output is correct
13 Correct 254 ms 13908 KB Output is correct
14 Correct 257 ms 14176 KB Output is correct
15 Correct 538 ms 15268 KB Output is correct
16 Correct 325 ms 14164 KB Output is correct
17 Correct 316 ms 14216 KB Output is correct
18 Correct 114 ms 16192 KB Output is correct
19 Correct 138 ms 12968 KB Output is correct
20 Correct 356 ms 14728 KB Output is correct
21 Correct 751 ms 18256 KB Output is correct
22 Correct 368 ms 18384 KB Output is correct
23 Correct 364 ms 17236 KB Output is correct
24 Correct 365 ms 17156 KB Output is correct
25 Correct 330 ms 19024 KB Output is correct
26 Correct 425 ms 17660 KB Output is correct
27 Correct 412 ms 17656 KB Output is correct
28 Correct 132 ms 20140 KB Output is correct
29 Correct 167 ms 16208 KB Output is correct
30 Correct 504 ms 18260 KB Output is correct
31 Correct 613 ms 18056 KB Output is correct
32 Correct 453 ms 18048 KB Output is correct
33 Correct 273 ms 17236 KB Output is correct
34 Correct 346 ms 17236 KB Output is correct
35 Correct 398 ms 17492 KB Output is correct
36 Correct 124 ms 16224 KB Output is correct
37 Correct 575 ms 18004 KB Output is correct
38 Correct 178 ms 16212 KB Output is correct
39 Correct 349 ms 17308 KB Output is correct
40 Correct 361 ms 17212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 48 ms 16180 KB Output is correct
12 Correct 48 ms 16188 KB Output is correct
13 Correct 58 ms 15940 KB Output is correct
14 Correct 79 ms 15976 KB Output is correct
15 Correct 56 ms 16196 KB Output is correct
16 Correct 79 ms 15940 KB Output is correct
17 Correct 80 ms 15936 KB Output is correct
18 Correct 40 ms 16196 KB Output is correct
19 Correct 44 ms 15940 KB Output is correct
20 Correct 51 ms 15940 KB Output is correct
21 Correct 64 ms 16008 KB Output is correct
22 Correct 82 ms 15932 KB Output is correct
23 Correct 50 ms 15940 KB Output is correct
24 Correct 76 ms 16132 KB Output is correct
25 Correct 68 ms 15960 KB Output is correct
26 Correct 37 ms 15940 KB Output is correct
27 Correct 46 ms 15956 KB Output is correct
28 Correct 51 ms 15932 KB Output is correct
29 Correct 57 ms 15956 KB Output is correct
30 Correct 81 ms 15936 KB Output is correct
31 Correct 50 ms 15944 KB Output is correct
32 Correct 82 ms 15940 KB Output is correct
33 Correct 66 ms 15932 KB Output is correct
34 Correct 38 ms 15936 KB Output is correct
35 Correct 67 ms 15936 KB Output is correct
36 Correct 71 ms 15936 KB Output is correct
37 Correct 63 ms 15944 KB Output is correct
38 Correct 62 ms 15948 KB Output is correct
39 Correct 61 ms 15940 KB Output is correct
40 Correct 59 ms 15932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 346 ms 15188 KB Output is correct
12 Correct 332 ms 14672 KB Output is correct
13 Correct 254 ms 13908 KB Output is correct
14 Correct 257 ms 14176 KB Output is correct
15 Correct 538 ms 15268 KB Output is correct
16 Correct 325 ms 14164 KB Output is correct
17 Correct 316 ms 14216 KB Output is correct
18 Correct 114 ms 16192 KB Output is correct
19 Correct 138 ms 12968 KB Output is correct
20 Correct 356 ms 14728 KB Output is correct
21 Correct 751 ms 18256 KB Output is correct
22 Correct 368 ms 18384 KB Output is correct
23 Correct 364 ms 17236 KB Output is correct
24 Correct 365 ms 17156 KB Output is correct
25 Correct 330 ms 19024 KB Output is correct
26 Correct 425 ms 17660 KB Output is correct
27 Correct 412 ms 17656 KB Output is correct
28 Correct 132 ms 20140 KB Output is correct
29 Correct 167 ms 16208 KB Output is correct
30 Correct 504 ms 18260 KB Output is correct
31 Correct 613 ms 18056 KB Output is correct
32 Correct 453 ms 18048 KB Output is correct
33 Correct 273 ms 17236 KB Output is correct
34 Correct 346 ms 17236 KB Output is correct
35 Correct 398 ms 17492 KB Output is correct
36 Correct 124 ms 16224 KB Output is correct
37 Correct 575 ms 18004 KB Output is correct
38 Correct 178 ms 16212 KB Output is correct
39 Correct 349 ms 17308 KB Output is correct
40 Correct 361 ms 17212 KB Output is correct
41 Correct 48 ms 16180 KB Output is correct
42 Correct 48 ms 16188 KB Output is correct
43 Correct 58 ms 15940 KB Output is correct
44 Correct 79 ms 15976 KB Output is correct
45 Correct 56 ms 16196 KB Output is correct
46 Correct 79 ms 15940 KB Output is correct
47 Correct 80 ms 15936 KB Output is correct
48 Correct 40 ms 16196 KB Output is correct
49 Correct 44 ms 15940 KB Output is correct
50 Correct 51 ms 15940 KB Output is correct
51 Correct 64 ms 16008 KB Output is correct
52 Correct 82 ms 15932 KB Output is correct
53 Correct 50 ms 15940 KB Output is correct
54 Correct 76 ms 16132 KB Output is correct
55 Correct 68 ms 15960 KB Output is correct
56 Correct 37 ms 15940 KB Output is correct
57 Correct 46 ms 15956 KB Output is correct
58 Correct 51 ms 15932 KB Output is correct
59 Correct 57 ms 15956 KB Output is correct
60 Correct 81 ms 15936 KB Output is correct
61 Correct 50 ms 15944 KB Output is correct
62 Correct 82 ms 15940 KB Output is correct
63 Correct 66 ms 15932 KB Output is correct
64 Correct 38 ms 15936 KB Output is correct
65 Correct 67 ms 15936 KB Output is correct
66 Correct 71 ms 15936 KB Output is correct
67 Correct 63 ms 15944 KB Output is correct
68 Correct 62 ms 15948 KB Output is correct
69 Correct 61 ms 15940 KB Output is correct
70 Correct 59 ms 15932 KB Output is correct
71 Correct 393 ms 40256 KB Output is correct
72 Correct 422 ms 40512 KB Output is correct
73 Correct 625 ms 39020 KB Output is correct
74 Correct 1046 ms 39220 KB Output is correct
75 Correct 559 ms 41284 KB Output is correct
76 Correct 909 ms 39748 KB Output is correct
77 Correct 796 ms 39492 KB Output is correct
78 Correct 241 ms 43336 KB Output is correct
79 Correct 332 ms 37180 KB Output is correct
80 Correct 458 ms 40508 KB Output is correct
81 Correct 749 ms 40196 KB Output is correct
82 Correct 1060 ms 39256 KB Output is correct
83 Correct 448 ms 38744 KB Output is correct
84 Correct 818 ms 39228 KB Output is correct
85 Correct 768 ms 39480 KB Output is correct
86 Correct 218 ms 37232 KB Output is correct
87 Correct 362 ms 40312 KB Output is correct
88 Correct 288 ms 37208 KB Output is correct
89 Correct 549 ms 39048 KB Output is correct
90 Correct 803 ms 39392 KB Output is correct
91 Correct 477 ms 38472 KB Output is correct
92 Correct 896 ms 39744 KB Output is correct
93 Correct 717 ms 39540 KB Output is correct
94 Correct 198 ms 37308 KB Output is correct
95 Correct 638 ms 39396 KB Output is correct
96 Correct 655 ms 39488 KB Output is correct
97 Correct 623 ms 39500 KB Output is correct
98 Correct 615 ms 39492 KB Output is correct
99 Correct 633 ms 39484 KB Output is correct
100 Correct 616 ms 39488 KB Output is correct