# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568562 | 2022-05-25T17:04:33 Z | FEDIKUS | Snake Escaping (JOI18_snake_escaping) | C++17 | 661 ms | 39928 KB |
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define xx first #define yy second #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++) #define fb(i,s,f) for(ll (i)=s-1;(i)>=f;(i)--) #define ffi(i,s,f) for(ll (i)=s;(i)<=(f);(i)++) #define fbi(i,s,f) for(ll (i)=s;(i)>=(f);(i)--) #define srt(a) sort(a.begin(),a.end()); #define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>()) #define lb(a,x) lower_bound(a.begin(),a.end(),x) #define ub(a,x) upper_bound(a.begin(),a.end(),x) #define fnd(a,x) find(a.begin(),a.end(),x) #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; typedef pair<ll,ll> pll; typedef string str; const ll logg=21; ll sub[1LL<<logg],sup[1LL<<logg]; ll com(ll a){ return a^((1LL<<logg)-1); } void solve(){ ll l,q; cin>>l>>q; str s; cin>>s; ff(mask,0,(1LL<<l)) sub[mask]=s[mask]-'0'; ff(i,0,logg) ff(mask,0,(1LL<<logg)) if((1LL<<i)&mask) sub[mask]+=sub[mask^(1LL<<i)]; ff(mask,0,(1LL<<l)) sup[mask]=s[mask]-'0'; ff(i,0,logg) ff(mask,0,(1LL<<logg)) if((1LL<<i)&com(mask)) sup[mask]+=sup[mask^(1LL<<i)]; while(q--){ str t; cin>>t; ll one=0,zero=0; for(char i:t) if(i=='0') zero++; else if(i=='1') one++; ll res=0; if(one<=6){ ll mask=0; ll nfixed=0; ff(i,0,l){ if(t[i]=='1') mask+=(1LL<<(l-i-1)); if(t[i]=='?') nfixed+=(1LL<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ if((one-__builtin_popcount(submask|nfixed))&1) res-=sub[submask|nfixed]; else res+=sub[submask|nfixed]; if(submask==0) break; } }else if(zero<=6){ ll mask=0; ll ones=0; ff(i,0,l){ if(t[i]=='0') mask+=(1LL<<(l-i-1)); if(t[i]=='1') ones+=(1LL<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ if(__builtin_popcount(submask)&1) res-=sup[submask|ones]; else res+=sup[submask|ones]; if(submask==0) break; } }else{ ll mask=0; ff(i,0,l){ if(t[i]=='?') mask+=(1LL<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ res+=s[submask]-'0'; if(submask==0) break; } } cout<<abs(res)<<"\n"; } } int main(){ ios; ll t=1; //cin>>t; while(t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 33208 KB | Output is correct |
2 | Correct | 124 ms | 33260 KB | Output is correct |
3 | Correct | 129 ms | 33140 KB | Output is correct |
4 | Correct | 113 ms | 33100 KB | Output is correct |
5 | Correct | 114 ms | 33120 KB | Output is correct |
6 | Correct | 128 ms | 33116 KB | Output is correct |
7 | Correct | 128 ms | 33144 KB | Output is correct |
8 | Correct | 111 ms | 33132 KB | Output is correct |
9 | Correct | 111 ms | 33136 KB | Output is correct |
10 | Correct | 128 ms | 33140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 33208 KB | Output is correct |
2 | Correct | 124 ms | 33260 KB | Output is correct |
3 | Correct | 129 ms | 33140 KB | Output is correct |
4 | Correct | 113 ms | 33100 KB | Output is correct |
5 | Correct | 114 ms | 33120 KB | Output is correct |
6 | Correct | 128 ms | 33116 KB | Output is correct |
7 | Correct | 128 ms | 33144 KB | Output is correct |
8 | Correct | 111 ms | 33132 KB | Output is correct |
9 | Correct | 111 ms | 33136 KB | Output is correct |
10 | Correct | 128 ms | 33140 KB | Output is correct |
11 | Correct | 463 ms | 37860 KB | Output is correct |
12 | Correct | 332 ms | 37608 KB | Output is correct |
13 | Correct | 389 ms | 36856 KB | Output is correct |
14 | Correct | 405 ms | 36832 KB | Output is correct |
15 | Correct | 339 ms | 37828 KB | Output is correct |
16 | Correct | 399 ms | 37196 KB | Output is correct |
17 | Correct | 423 ms | 37052 KB | Output is correct |
18 | Correct | 295 ms | 38920 KB | Output is correct |
19 | Correct | 438 ms | 35876 KB | Output is correct |
20 | Correct | 397 ms | 37544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 33208 KB | Output is correct |
2 | Correct | 124 ms | 33260 KB | Output is correct |
3 | Correct | 129 ms | 33140 KB | Output is correct |
4 | Correct | 113 ms | 33100 KB | Output is correct |
5 | Correct | 114 ms | 33120 KB | Output is correct |
6 | Correct | 128 ms | 33116 KB | Output is correct |
7 | Correct | 128 ms | 33144 KB | Output is correct |
8 | Correct | 111 ms | 33132 KB | Output is correct |
9 | Correct | 111 ms | 33136 KB | Output is correct |
10 | Correct | 128 ms | 33140 KB | Output is correct |
11 | Correct | 463 ms | 37860 KB | Output is correct |
12 | Correct | 332 ms | 37608 KB | Output is correct |
13 | Correct | 389 ms | 36856 KB | Output is correct |
14 | Correct | 405 ms | 36832 KB | Output is correct |
15 | Correct | 339 ms | 37828 KB | Output is correct |
16 | Correct | 399 ms | 37196 KB | Output is correct |
17 | Correct | 423 ms | 37052 KB | Output is correct |
18 | Correct | 295 ms | 38920 KB | Output is correct |
19 | Correct | 438 ms | 35876 KB | Output is correct |
20 | Correct | 397 ms | 37544 KB | Output is correct |
21 | Correct | 631 ms | 38596 KB | Output is correct |
22 | Correct | 361 ms | 38344 KB | Output is correct |
23 | Correct | 478 ms | 37332 KB | Output is correct |
24 | Correct | 430 ms | 37160 KB | Output is correct |
25 | Correct | 391 ms | 39192 KB | Output is correct |
26 | Correct | 513 ms | 37400 KB | Output is correct |
27 | Correct | 484 ms | 37380 KB | Output is correct |
28 | Correct | 346 ms | 39928 KB | Output is correct |
29 | Correct | 570 ms | 35600 KB | Output is correct |
30 | Correct | 469 ms | 37796 KB | Output is correct |
31 | Correct | 440 ms | 37652 KB | Output is correct |
32 | Correct | 446 ms | 37624 KB | Output is correct |
33 | Correct | 411 ms | 36508 KB | Output is correct |
34 | Correct | 464 ms | 36668 KB | Output is correct |
35 | Correct | 466 ms | 36820 KB | Output is correct |
36 | Correct | 289 ms | 35332 KB | Output is correct |
37 | Correct | 342 ms | 37380 KB | Output is correct |
38 | Correct | 552 ms | 35384 KB | Output is correct |
39 | Correct | 661 ms | 36596 KB | Output is correct |
40 | Correct | 516 ms | 36368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 33208 KB | Output is correct |
2 | Correct | 124 ms | 33260 KB | Output is correct |
3 | Correct | 129 ms | 33140 KB | Output is correct |
4 | Correct | 113 ms | 33100 KB | Output is correct |
5 | Correct | 114 ms | 33120 KB | Output is correct |
6 | Correct | 128 ms | 33116 KB | Output is correct |
7 | Correct | 128 ms | 33144 KB | Output is correct |
8 | Correct | 111 ms | 33132 KB | Output is correct |
9 | Correct | 111 ms | 33136 KB | Output is correct |
10 | Correct | 128 ms | 33140 KB | Output is correct |
11 | Correct | 144 ms | 34780 KB | Output is correct |
12 | Correct | 138 ms | 34840 KB | Output is correct |
13 | Incorrect | 145 ms | 34676 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 33208 KB | Output is correct |
2 | Correct | 124 ms | 33260 KB | Output is correct |
3 | Correct | 129 ms | 33140 KB | Output is correct |
4 | Correct | 113 ms | 33100 KB | Output is correct |
5 | Correct | 114 ms | 33120 KB | Output is correct |
6 | Correct | 128 ms | 33116 KB | Output is correct |
7 | Correct | 128 ms | 33144 KB | Output is correct |
8 | Correct | 111 ms | 33132 KB | Output is correct |
9 | Correct | 111 ms | 33136 KB | Output is correct |
10 | Correct | 128 ms | 33140 KB | Output is correct |
11 | Correct | 463 ms | 37860 KB | Output is correct |
12 | Correct | 332 ms | 37608 KB | Output is correct |
13 | Correct | 389 ms | 36856 KB | Output is correct |
14 | Correct | 405 ms | 36832 KB | Output is correct |
15 | Correct | 339 ms | 37828 KB | Output is correct |
16 | Correct | 399 ms | 37196 KB | Output is correct |
17 | Correct | 423 ms | 37052 KB | Output is correct |
18 | Correct | 295 ms | 38920 KB | Output is correct |
19 | Correct | 438 ms | 35876 KB | Output is correct |
20 | Correct | 397 ms | 37544 KB | Output is correct |
21 | Correct | 631 ms | 38596 KB | Output is correct |
22 | Correct | 361 ms | 38344 KB | Output is correct |
23 | Correct | 478 ms | 37332 KB | Output is correct |
24 | Correct | 430 ms | 37160 KB | Output is correct |
25 | Correct | 391 ms | 39192 KB | Output is correct |
26 | Correct | 513 ms | 37400 KB | Output is correct |
27 | Correct | 484 ms | 37380 KB | Output is correct |
28 | Correct | 346 ms | 39928 KB | Output is correct |
29 | Correct | 570 ms | 35600 KB | Output is correct |
30 | Correct | 469 ms | 37796 KB | Output is correct |
31 | Correct | 440 ms | 37652 KB | Output is correct |
32 | Correct | 446 ms | 37624 KB | Output is correct |
33 | Correct | 411 ms | 36508 KB | Output is correct |
34 | Correct | 464 ms | 36668 KB | Output is correct |
35 | Correct | 466 ms | 36820 KB | Output is correct |
36 | Correct | 289 ms | 35332 KB | Output is correct |
37 | Correct | 342 ms | 37380 KB | Output is correct |
38 | Correct | 552 ms | 35384 KB | Output is correct |
39 | Correct | 661 ms | 36596 KB | Output is correct |
40 | Correct | 516 ms | 36368 KB | Output is correct |
41 | Correct | 144 ms | 34780 KB | Output is correct |
42 | Correct | 138 ms | 34840 KB | Output is correct |
43 | Incorrect | 145 ms | 34676 KB | Output isn't correct |
44 | Halted | 0 ms | 0 KB | - |