Submission #920219

# Submission time Handle Problem Language Result Execution time Memory
920219 2024-02-02T09:40:55 Z Unforgettablepl Snake Escaping (JOI18_snake_escaping) C++17
58 / 100
2000 ms 25680 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;

#define int long long

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

inline 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;
}

inline 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:14: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]
   14 |     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:27: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]
   27 |     for(int bit=0;bit<s.size();bit++){
      |                   ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18520 KB Output is correct
2 Correct 28 ms 18520 KB Output is correct
3 Correct 32 ms 18520 KB Output is correct
4 Correct 29 ms 18520 KB Output is correct
5 Correct 30 ms 18520 KB Output is correct
6 Correct 29 ms 18520 KB Output is correct
7 Correct 28 ms 18520 KB Output is correct
8 Correct 29 ms 18520 KB Output is correct
9 Correct 31 ms 18520 KB Output is correct
10 Correct 30 ms 18520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18520 KB Output is correct
2 Correct 28 ms 18520 KB Output is correct
3 Correct 32 ms 18520 KB Output is correct
4 Correct 29 ms 18520 KB Output is correct
5 Correct 30 ms 18520 KB Output is correct
6 Correct 29 ms 18520 KB Output is correct
7 Correct 28 ms 18520 KB Output is correct
8 Correct 29 ms 18520 KB Output is correct
9 Correct 31 ms 18520 KB Output is correct
10 Correct 30 ms 18520 KB Output is correct
11 Correct 209 ms 22608 KB Output is correct
12 Correct 1624 ms 22684 KB Output is correct
13 Execution timed out 2028 ms 21384 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18520 KB Output is correct
2 Correct 28 ms 18520 KB Output is correct
3 Correct 32 ms 18520 KB Output is correct
4 Correct 29 ms 18520 KB Output is correct
5 Correct 30 ms 18520 KB Output is correct
6 Correct 29 ms 18520 KB Output is correct
7 Correct 28 ms 18520 KB Output is correct
8 Correct 29 ms 18520 KB Output is correct
9 Correct 31 ms 18520 KB Output is correct
10 Correct 30 ms 18520 KB Output is correct
11 Correct 209 ms 22608 KB Output is correct
12 Correct 1624 ms 22684 KB Output is correct
13 Execution timed out 2028 ms 21384 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18520 KB Output is correct
2 Correct 28 ms 18520 KB Output is correct
3 Correct 32 ms 18520 KB Output is correct
4 Correct 29 ms 18520 KB Output is correct
5 Correct 30 ms 18520 KB Output is correct
6 Correct 29 ms 18520 KB Output is correct
7 Correct 28 ms 18520 KB Output is correct
8 Correct 29 ms 18520 KB Output is correct
9 Correct 31 ms 18520 KB Output is correct
10 Correct 30 ms 18520 KB Output is correct
11 Correct 64 ms 25476 KB Output is correct
12 Correct 65 ms 25168 KB Output is correct
13 Correct 177 ms 25088 KB Output is correct
14 Correct 347 ms 25168 KB Output is correct
15 Correct 120 ms 25360 KB Output is correct
16 Correct 323 ms 25232 KB Output is correct
17 Correct 233 ms 25168 KB Output is correct
18 Correct 45 ms 25424 KB Output is correct
19 Correct 55 ms 25052 KB Output is correct
20 Correct 56 ms 25168 KB Output is correct
21 Correct 187 ms 25168 KB Output is correct
22 Correct 299 ms 25080 KB Output is correct
23 Correct 110 ms 25168 KB Output is correct
24 Correct 279 ms 25132 KB Output is correct
25 Correct 246 ms 25680 KB Output is correct
26 Correct 45 ms 24988 KB Output is correct
27 Correct 54 ms 25308 KB Output is correct
28 Correct 77 ms 24920 KB Output is correct
29 Correct 167 ms 25152 KB Output is correct
30 Correct 245 ms 25424 KB Output is correct
31 Correct 116 ms 25168 KB Output is correct
32 Correct 300 ms 25052 KB Output is correct
33 Correct 229 ms 25168 KB Output is correct
34 Correct 46 ms 24920 KB Output is correct
35 Correct 186 ms 25424 KB Output is correct
36 Correct 178 ms 25168 KB Output is correct
37 Correct 184 ms 25168 KB Output is correct
38 Correct 175 ms 25168 KB Output is correct
39 Correct 180 ms 25204 KB Output is correct
40 Correct 178 ms 25060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18520 KB Output is correct
2 Correct 28 ms 18520 KB Output is correct
3 Correct 32 ms 18520 KB Output is correct
4 Correct 29 ms 18520 KB Output is correct
5 Correct 30 ms 18520 KB Output is correct
6 Correct 29 ms 18520 KB Output is correct
7 Correct 28 ms 18520 KB Output is correct
8 Correct 29 ms 18520 KB Output is correct
9 Correct 31 ms 18520 KB Output is correct
10 Correct 30 ms 18520 KB Output is correct
11 Correct 209 ms 22608 KB Output is correct
12 Correct 1624 ms 22684 KB Output is correct
13 Execution timed out 2028 ms 21384 KB Time limit exceeded
14 Halted 0 ms 0 KB -