Submission #568566

#TimeUsernameProblemLanguageResultExecution timeMemory
568566FEDIKUSSnake Escaping (JOI18_snake_escaping)C++17
100 / 100
1368 ms47440 KiB
#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=20; 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; ll fixed=0; ff(i,0,l){ if(t[i]=='?') mask+=(1LL<<(l-i-1)); else if(t[i]=='1') fixed+=(1LL<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ res+=s[submask|fixed]-'0'; if(submask==0) break; } } cout<<abs(res)<<"\n"; } } int main(){ ios; ll t=1; //cin>>t; while(t--) solve(); return 0; }

Compilation message (stderr)

snake_escaping.cpp: In function 'void solve()':
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:40:5: note: in expansion of macro 'ff'
   40 |     ff(mask,0,(1LL<<l)) sub[mask]=s[mask]-'0';
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:41:5: note: in expansion of macro 'ff'
   41 |     ff(i,0,logg) ff(mask,0,(1LL<<logg)) if((1LL<<i)&mask) sub[mask]+=sub[mask^(1LL<<i)];
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:41:18: note: in expansion of macro 'ff'
   41 |     ff(i,0,logg) ff(mask,0,(1LL<<logg)) if((1LL<<i)&mask) sub[mask]+=sub[mask^(1LL<<i)];
      |                  ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:42:5: note: in expansion of macro 'ff'
   42 |     ff(mask,0,(1LL<<l)) sup[mask]=s[mask]-'0';
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:43:5: note: in expansion of macro 'ff'
   43 |     ff(i,0,logg) ff(mask,0,(1LL<<logg)) if((1LL<<i)&com(mask)) sup[mask]+=sup[mask^(1LL<<i)];
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:43:18: note: in expansion of macro 'ff'
   43 |     ff(i,0,logg) ff(mask,0,(1LL<<logg)) if((1LL<<i)&com(mask)) sup[mask]+=sup[mask^(1LL<<i)];
      |                  ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:53:13: note: in expansion of macro 'ff'
   53 |             ff(i,0,l){
      |             ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:65:13: note: in expansion of macro 'ff'
   65 |             ff(i,0,l){
      |             ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:77:13: note: in expansion of macro 'ff'
   77 |             ff(i,0,l){
      |             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...