Submission #568559

#TimeUsernameProblemLanguageResultExecution timeMemory
568559FEDIKUSSnake Escaping (JOI18_snake_escaping)C++17
22 / 100
555 ms36448 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(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 (stderr)

snake_escaping.cpp: In function 'void solve()':
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:40:5: note: in expansion of macro 'ff'
   40 |     ff(mask,0,(1<<l)) sub[mask]=s[mask]-'0';
      |     ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:41:5: note: in expansion of macro 'ff'
   41 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&mask) sub[mask]+=sub[mask^(1<<i)];
      |     ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:41:18: note: in expansion of macro 'ff'
   41 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&mask) sub[mask]+=sub[mask^(1<<i)];
      |                  ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:42:5: note: in expansion of macro 'ff'
   42 |     ff(mask,0,(1<<l)) sup[mask]=s[mask]-'0';
      |     ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:43:5: note: in expansion of macro 'ff'
   43 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&com(mask)) sup[mask]+=sup[mask^(1<<i)];
      |     ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:43:18: note: in expansion of macro 'ff'
   43 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&com(mask)) sup[mask]+=sup[mask^(1<<i)];
      |                  ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:53:13: note: in expansion of macro 'ff'
   53 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                                 ~~~^~~~
snake_escaping.cpp:53:13: note: in expansion of macro 'ff'
   53 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:65:13: note: in expansion of macro 'ff'
   65 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                                 ~~~^~~~
snake_escaping.cpp:65:13: note: in expansion of macro 'ff'
   65 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                           ^
snake_escaping.cpp:76:13: note: in expansion of macro 'ff'
   76 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define ff(i,s,f) for(int (i)=s;(i)<(f);(i)++)
      |                                 ~~~^~~~
snake_escaping.cpp:76:13: note: in expansion of macro 'ff'
   76 |             ff(i,0,t.size()){
      |             ^~
#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...