Submission #920217

# Submission time Handle Problem Language Result Execution time Memory
920217 2024-02-02T09:37:01 Z Unforgettablepl Snake Escaping (JOI18_snake_escaping) C++17
58 / 100
2000 ms 33376 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int DP1[1048576];
int DP2[1048576];
int arr[1048576];

int applymaskques(const string &s,int mask){
    int ans = 0;
    for(int bit=0;bit<s.size();bit++){
        if(s[bit]=='?'){
            if(mask&1)ans|=(1<<bit);
            mask>>=1;
        } else {
            if(s[bit]=='1')ans|=(1<<bit);
        }
    }
    return ans;
}

int applymask(const string &s,int mask,char to){
    int ans = 0;
    for(int bit=0;bit<s.size();bit++){
        if(s[bit]=='?'){
            if(to=='1')ans|=(1<<bit);
        } else if(s[bit]==to){
            if(mask&1)ans|=(1<<bit);
            mask>>=1;
        } else {
            if(to=='0')ans|=(1<<bit);
        }
    }
    return ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int l,q;
    cin >> l >> q;
    for(int mask=0;mask<(1<<l);mask++){
        char a;cin>>a;a-='0';
        DP1[mask]=DP2[mask]=arr[mask]=a;
    }
    for(int bit=0;bit<20;bit++){
        for(int mask=0;mask<(1<<20);mask++){
            if(mask&(1<<bit)){
                DP2[mask^(1<<bit)]+=DP2[mask];
            } else {
                DP1[mask|(1<<bit)]+=DP1[mask];
            }
        }
    }
    for(int i=1;i<=q;i++){
        string s;cin>>s;
        reverse(s.begin(),s.end());
        int c1=0,c0=0,cq=0;
        for(char&j:s)if(j=='1')c1++;
        for(char&j:s)if(j=='0')c0++;
        for(char&j:s)if(j=='?')cq++;
        if(c0<=6){
            int ans = 0;
            for(int mask=0;mask<(1<<c0);mask++){
                if(__builtin_parity(mask)){
                    ans-=DP2[applymask(s,mask,'0')];
                } else {
                    ans+=DP2[applymask(s,mask,'0')];
                }
            }
            cout<<ans<<'\n';
            continue;
        }
        if(c1<=6){
            int ans = 0;
            for(int mask=0;mask<(1<<c1);mask++){
                if(__builtin_parity(mask)==(c1&1)){
                    ans+=DP1[applymask(s,mask,'1')];
                } else {
                    ans-=DP1[applymask(s,mask,'1')];
                }
            }
            cout<<ans<<'\n';
            continue;
        }
        if(cq<=6){
            int ans = 0;
            for(int mask=0;mask<(1<<cq);mask++){
                ans+=arr[applymaskques(s,mask)];
            }
            cout<<ans<<'\n';
            continue;
        }
    }
}

Compilation message

snake_escaping.cpp: In function 'long long int applymaskques(const string&, long long int)':
snake_escaping.cpp:12:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int bit=0;bit<s.size();bit++){
      |                   ~~~^~~~~~~~~
snake_escaping.cpp: In function 'long long int applymask(const string&, long long int, char)':
snake_escaping.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int bit=0;bit<s.size();bit++){
      |                   ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 18520 KB Output is correct
2 Correct 39 ms 18520 KB Output is correct
3 Correct 36 ms 18524 KB Output is correct
4 Correct 38 ms 18748 KB Output is correct
5 Correct 32 ms 18520 KB Output is correct
6 Correct 32 ms 18768 KB Output is correct
7 Correct 33 ms 18520 KB Output is correct
8 Correct 32 ms 18520 KB Output is correct
9 Correct 35 ms 18520 KB Output is correct
10 Correct 39 ms 18520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 18520 KB Output is correct
2 Correct 39 ms 18520 KB Output is correct
3 Correct 36 ms 18524 KB Output is correct
4 Correct 38 ms 18748 KB Output is correct
5 Correct 32 ms 18520 KB Output is correct
6 Correct 32 ms 18768 KB Output is correct
7 Correct 33 ms 18520 KB Output is correct
8 Correct 32 ms 18520 KB Output is correct
9 Correct 35 ms 18520 KB Output is correct
10 Correct 39 ms 18520 KB Output is correct
11 Correct 253 ms 33376 KB Output is correct
12 Correct 1979 ms 33056 KB Output is correct
13 Execution timed out 2033 ms 29596 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 18520 KB Output is correct
2 Correct 39 ms 18520 KB Output is correct
3 Correct 36 ms 18524 KB Output is correct
4 Correct 38 ms 18748 KB Output is correct
5 Correct 32 ms 18520 KB Output is correct
6 Correct 32 ms 18768 KB Output is correct
7 Correct 33 ms 18520 KB Output is correct
8 Correct 32 ms 18520 KB Output is correct
9 Correct 35 ms 18520 KB Output is correct
10 Correct 39 ms 18520 KB Output is correct
11 Correct 253 ms 33376 KB Output is correct
12 Correct 1979 ms 33056 KB Output is correct
13 Execution timed out 2033 ms 29596 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 18520 KB Output is correct
2 Correct 39 ms 18520 KB Output is correct
3 Correct 36 ms 18524 KB Output is correct
4 Correct 38 ms 18748 KB Output is correct
5 Correct 32 ms 18520 KB Output is correct
6 Correct 32 ms 18768 KB Output is correct
7 Correct 33 ms 18520 KB Output is correct
8 Correct 32 ms 18520 KB Output is correct
9 Correct 35 ms 18520 KB Output is correct
10 Correct 39 ms 18520 KB Output is correct
11 Correct 68 ms 27216 KB Output is correct
12 Correct 93 ms 27348 KB Output is correct
13 Correct 188 ms 27236 KB Output is correct
14 Correct 393 ms 27284 KB Output is correct
15 Correct 133 ms 27276 KB Output is correct
16 Correct 413 ms 27096 KB Output is correct
17 Correct 283 ms 27096 KB Output is correct
18 Correct 48 ms 27476 KB Output is correct
19 Correct 61 ms 26964 KB Output is correct
20 Correct 59 ms 27216 KB Output is correct
21 Correct 195 ms 27216 KB Output is correct
22 Correct 348 ms 27104 KB Output is correct
23 Correct 138 ms 27328 KB Output is correct
24 Correct 339 ms 27308 KB Output is correct
25 Correct 300 ms 27092 KB Output is correct
26 Correct 52 ms 27220 KB Output is correct
27 Correct 66 ms 27216 KB Output is correct
28 Correct 83 ms 27032 KB Output is correct
29 Correct 214 ms 27232 KB Output is correct
30 Correct 298 ms 27108 KB Output is correct
31 Correct 128 ms 27344 KB Output is correct
32 Correct 353 ms 27216 KB Output is correct
33 Correct 274 ms 27104 KB Output is correct
34 Correct 52 ms 27124 KB Output is correct
35 Correct 219 ms 27216 KB Output is correct
36 Correct 210 ms 27312 KB Output is correct
37 Correct 203 ms 27216 KB Output is correct
38 Correct 198 ms 27216 KB Output is correct
39 Correct 197 ms 27100 KB Output is correct
40 Correct 196 ms 27216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 18520 KB Output is correct
2 Correct 39 ms 18520 KB Output is correct
3 Correct 36 ms 18524 KB Output is correct
4 Correct 38 ms 18748 KB Output is correct
5 Correct 32 ms 18520 KB Output is correct
6 Correct 32 ms 18768 KB Output is correct
7 Correct 33 ms 18520 KB Output is correct
8 Correct 32 ms 18520 KB Output is correct
9 Correct 35 ms 18520 KB Output is correct
10 Correct 39 ms 18520 KB Output is correct
11 Correct 253 ms 33376 KB Output is correct
12 Correct 1979 ms 33056 KB Output is correct
13 Execution timed out 2033 ms 29596 KB Time limit exceeded
14 Halted 0 ms 0 KB -