# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568559 | 2022-05-25T16:57:16 Z | FEDIKUS | Snake Escaping (JOI18_snake_escaping) | C++17 | 555 ms | 36448 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(int (i)=s;(i)<(f);(i)++) #define fb(i,s,f) for(int (i)=s-1;(i)>=f;(i)--) #define ffi(i,s,f) for(int (i)=s;(i)<=(f);(i)++) #define fbi(i,s,f) for(int (i)=s;(i)>=(f);(i)--) #define srt(a) sort(a.begin(),a.end()); #define srtg(a,int) sort(a.begin(),a.end(),greater<int>()) #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<int,int> pii; typedef pair<ll,ll> pll; typedef string str; const int logg=21; int sub[1<<logg],sup[1<<logg]; int com(int a){ return a^((1<<logg)-1); } void solve(){ int l,q; cin>>l>>q; str s; cin>>s; ff(mask,0,(1<<l)) sub[mask]=s[mask]-'0'; ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&mask) sub[mask]+=sub[mask^(1<<i)]; ff(mask,0,(1<<l)) sup[mask]=s[mask]-'0'; ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&com(mask)) sup[mask]+=sup[mask^(1<<i)]; while(q--){ str t; cin>>t; int one=0,zero=0; for(char i:t) if(i=='0') zero++; else if(i=='1') one++; int res=0; if(one<=6){ int mask=0; int nfixed=0; ff(i,0,t.size()){ if(t[i]=='1') mask+=(1<<(l-i-1)); if(t[i]=='?') nfixed+=(1<<(l-i-1)); } for(int 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){ int mask=0; int ones=0; ff(i,0,t.size()){ if(t[i]=='0') mask+=(1<<(l-i-1)); if(t[i]=='1') ones+=(1<<(l-i-1)); } for(int 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{ int mask=0; ff(i,0,t.size()){ if(t[i]=='?') mask+=(1<<(l-i-1)); } for(int submask=mask;;submask=(submask-1)&mask){ res+=s[submask]-'0'; if(submask==0) break; } } cout<<abs(res)<<"\n"; } } int main(){ ios; int t=1; //cin>>t; while(t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 16728 KB | Output is correct |
2 | Correct | 81 ms | 16728 KB | Output is correct |
3 | Correct | 80 ms | 16732 KB | Output is correct |
4 | Correct | 79 ms | 16716 KB | Output is correct |
5 | Correct | 82 ms | 16656 KB | Output is correct |
6 | Correct | 84 ms | 16736 KB | Output is correct |
7 | Correct | 81 ms | 16676 KB | Output is correct |
8 | Correct | 84 ms | 16728 KB | Output is correct |
9 | Correct | 84 ms | 16600 KB | Output is correct |
10 | Correct | 79 ms | 16720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 16728 KB | Output is correct |
2 | Correct | 81 ms | 16728 KB | Output is correct |
3 | Correct | 80 ms | 16732 KB | Output is correct |
4 | Correct | 79 ms | 16716 KB | Output is correct |
5 | Correct | 82 ms | 16656 KB | Output is correct |
6 | Correct | 84 ms | 16736 KB | Output is correct |
7 | Correct | 81 ms | 16676 KB | Output is correct |
8 | Correct | 84 ms | 16728 KB | Output is correct |
9 | Correct | 84 ms | 16600 KB | Output is correct |
10 | Correct | 79 ms | 16720 KB | Output is correct |
11 | Correct | 426 ms | 31488 KB | Output is correct |
12 | Correct | 343 ms | 31080 KB | Output is correct |
13 | Correct | 354 ms | 30332 KB | Output is correct |
14 | Correct | 343 ms | 30448 KB | Output is correct |
15 | Correct | 348 ms | 31384 KB | Output is correct |
16 | Correct | 370 ms | 30720 KB | Output is correct |
17 | Correct | 377 ms | 30636 KB | Output is correct |
18 | Correct | 253 ms | 32448 KB | Output is correct |
19 | Correct | 401 ms | 29548 KB | Output is correct |
20 | Correct | 383 ms | 31272 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 16728 KB | Output is correct |
2 | Correct | 81 ms | 16728 KB | Output is correct |
3 | Correct | 80 ms | 16732 KB | Output is correct |
4 | Correct | 79 ms | 16716 KB | Output is correct |
5 | Correct | 82 ms | 16656 KB | Output is correct |
6 | Correct | 84 ms | 16736 KB | Output is correct |
7 | Correct | 81 ms | 16676 KB | Output is correct |
8 | Correct | 84 ms | 16728 KB | Output is correct |
9 | Correct | 84 ms | 16600 KB | Output is correct |
10 | Correct | 79 ms | 16720 KB | Output is correct |
11 | Correct | 426 ms | 31488 KB | Output is correct |
12 | Correct | 343 ms | 31080 KB | Output is correct |
13 | Correct | 354 ms | 30332 KB | Output is correct |
14 | Correct | 343 ms | 30448 KB | Output is correct |
15 | Correct | 348 ms | 31384 KB | Output is correct |
16 | Correct | 370 ms | 30720 KB | Output is correct |
17 | Correct | 377 ms | 30636 KB | Output is correct |
18 | Correct | 253 ms | 32448 KB | Output is correct |
19 | Correct | 401 ms | 29548 KB | Output is correct |
20 | Correct | 383 ms | 31272 KB | Output is correct |
21 | Correct | 548 ms | 34376 KB | Output is correct |
22 | Correct | 366 ms | 34552 KB | Output is correct |
23 | Correct | 410 ms | 33616 KB | Output is correct |
24 | Correct | 409 ms | 33460 KB | Output is correct |
25 | Correct | 355 ms | 35444 KB | Output is correct |
26 | Correct | 434 ms | 34052 KB | Output is correct |
27 | Correct | 438 ms | 33944 KB | Output is correct |
28 | Correct | 288 ms | 36448 KB | Output is correct |
29 | Correct | 524 ms | 32368 KB | Output is correct |
30 | Correct | 377 ms | 34560 KB | Output is correct |
31 | Correct | 398 ms | 34508 KB | Output is correct |
32 | Correct | 417 ms | 34388 KB | Output is correct |
33 | Correct | 329 ms | 33308 KB | Output is correct |
34 | Correct | 438 ms | 33560 KB | Output is correct |
35 | Correct | 435 ms | 33848 KB | Output is correct |
36 | Correct | 278 ms | 32364 KB | Output is correct |
37 | Correct | 320 ms | 34464 KB | Output is correct |
38 | Correct | 495 ms | 32396 KB | Output is correct |
39 | Correct | 555 ms | 33712 KB | Output is correct |
40 | Correct | 461 ms | 33368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 16728 KB | Output is correct |
2 | Correct | 81 ms | 16728 KB | Output is correct |
3 | Correct | 80 ms | 16732 KB | Output is correct |
4 | Correct | 79 ms | 16716 KB | Output is correct |
5 | Correct | 82 ms | 16656 KB | Output is correct |
6 | Correct | 84 ms | 16736 KB | Output is correct |
7 | Correct | 81 ms | 16676 KB | Output is correct |
8 | Correct | 84 ms | 16728 KB | Output is correct |
9 | Correct | 84 ms | 16600 KB | Output is correct |
10 | Correct | 79 ms | 16720 KB | Output is correct |
11 | Correct | 100 ms | 20188 KB | Output is correct |
12 | Correct | 112 ms | 20164 KB | Output is correct |
13 | Incorrect | 113 ms | 20116 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 16728 KB | Output is correct |
2 | Correct | 81 ms | 16728 KB | Output is correct |
3 | Correct | 80 ms | 16732 KB | Output is correct |
4 | Correct | 79 ms | 16716 KB | Output is correct |
5 | Correct | 82 ms | 16656 KB | Output is correct |
6 | Correct | 84 ms | 16736 KB | Output is correct |
7 | Correct | 81 ms | 16676 KB | Output is correct |
8 | Correct | 84 ms | 16728 KB | Output is correct |
9 | Correct | 84 ms | 16600 KB | Output is correct |
10 | Correct | 79 ms | 16720 KB | Output is correct |
11 | Correct | 426 ms | 31488 KB | Output is correct |
12 | Correct | 343 ms | 31080 KB | Output is correct |
13 | Correct | 354 ms | 30332 KB | Output is correct |
14 | Correct | 343 ms | 30448 KB | Output is correct |
15 | Correct | 348 ms | 31384 KB | Output is correct |
16 | Correct | 370 ms | 30720 KB | Output is correct |
17 | Correct | 377 ms | 30636 KB | Output is correct |
18 | Correct | 253 ms | 32448 KB | Output is correct |
19 | Correct | 401 ms | 29548 KB | Output is correct |
20 | Correct | 383 ms | 31272 KB | Output is correct |
21 | Correct | 548 ms | 34376 KB | Output is correct |
22 | Correct | 366 ms | 34552 KB | Output is correct |
23 | Correct | 410 ms | 33616 KB | Output is correct |
24 | Correct | 409 ms | 33460 KB | Output is correct |
25 | Correct | 355 ms | 35444 KB | Output is correct |
26 | Correct | 434 ms | 34052 KB | Output is correct |
27 | Correct | 438 ms | 33944 KB | Output is correct |
28 | Correct | 288 ms | 36448 KB | Output is correct |
29 | Correct | 524 ms | 32368 KB | Output is correct |
30 | Correct | 377 ms | 34560 KB | Output is correct |
31 | Correct | 398 ms | 34508 KB | Output is correct |
32 | Correct | 417 ms | 34388 KB | Output is correct |
33 | Correct | 329 ms | 33308 KB | Output is correct |
34 | Correct | 438 ms | 33560 KB | Output is correct |
35 | Correct | 435 ms | 33848 KB | Output is correct |
36 | Correct | 278 ms | 32364 KB | Output is correct |
37 | Correct | 320 ms | 34464 KB | Output is correct |
38 | Correct | 495 ms | 32396 KB | Output is correct |
39 | Correct | 555 ms | 33712 KB | Output is correct |
40 | Correct | 461 ms | 33368 KB | Output is correct |
41 | Correct | 100 ms | 20188 KB | Output is correct |
42 | Correct | 112 ms | 20164 KB | Output is correct |
43 | Incorrect | 113 ms | 20116 KB | Output isn't correct |
44 | Halted | 0 ms | 0 KB | - |