Submission #848736

#TimeUsernameProblemLanguageResultExecution timeMemory
848736socpiteSnake Escaping (JOI18_snake_escaping)C++14
0 / 100
2050 ms4440 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = (1<<20); int n, q; int sub[maxn], super[maxn], val[maxn]; int gt(char x){ if(x == '0' || x == '1')return x-'0'; else return 2; } int main(){ ios::sync_with_stdio(false); cin >> n >> q; for(int i = 0; i < (1<<n); i++){ char x; cin >> x; sub[i] = super[i] = val[i] = x-'0'; } for(int i = 0; i < n; i++){ for(int j = 0; j < (1<<n); j++){ if(i&(1<<j)){ super[i^(1<<j)]+=super[i]; sub[i]+=sub[i^(1<<j)]; } } } while(q--){ string str; cin >> str; reverse(str.begin(), str.end()); int mask[3] = {0, 0, 0}; long long ans = 0; for(int i = 0; i < n; i++){ mask[gt(str[i])]|=(1<<i); } if(__builtin_popcount(mask[2]) <= 6){ for(int i = mask[2];;i=(i-1)&mask[2]){ ans += val[i^mask[1]]; if(!i)break; } } else if(__builtin_popcount(mask[1]) <= 6){ for(int i = mask[1];;i=(i-1)&mask[1]){ if(__builtin_popcount(i)&1)ans -= sub[mask[1]^i]; else ans += sub[mask[1]^i]; } } else { for(int i = mask[0];;i=(i-1)&mask[0]){ if(__builtin_popcount(i)&1)ans -= super[mask[1]^i]; else ans += super[mask[1]^i]; } } cout << ans << "\n"; } }
#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...