Submission #42382

#TimeUsernameProblemLanguageResultExecution timeMemory
42382RezwanArefin01Snake Escaping (JOI18_snake_escaping)C++14
65 / 100
2069 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; ll dp[1 << 20], ans; string b, s; int l, q; void recurr1(int i, int num, int tot) { if(i == l) { if(tot & 1) ans -= dp[num]; else ans += dp[num]; return; } if(s[i] == '0') { recurr1(i + 1, num << 1, tot); } else if(s[i] == '?') { recurr1(i + 1, num << 1 | 1, tot); } else { recurr1(i + 1, num << 1 | 1, tot); recurr1(i + 1, num << 1, tot + 1); } } void recurrw0t(int i, int num) { if(i == l) { ans += b[num] - '0'; return; } if(s[i] == '?') { recurrw0t(i + 1, num << 1 | 1); recurrw0t(i + 1, num << 1); } else recurrw0t(i + 1, (num << 1) + (s[i] == '1')); } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cin >> l >> q >> b; for(int i = 0; i < (1 << l); i++) { dp[i] = b[i] - '0'; } for(int i = 0; i < l; i++) { for(int j = 0; j < (1 << l); j++) { if(j >> i & 1) dp[j] += dp[j ^ (1 << i)]; } } while(q--) { cin >> s; int n0 = 0, n1 = 0, nw0t = 0; for(char c : s) { n0 += c == '0'; n1 += c == '1'; nw0t += c == '?'; } if(n1 == 0) { int num = 0; for(char c : s) num = (num << 1) + (c == '?'); cout << dp[num] << endl; } else if(nw0t == 0) { int num = 0; for(char c : s) num = (num << 1) + (c == '1'); cout << b[num] << endl; } else { ans = 0; if(nw0t <= n1) recurrw0t(0, 0); else recurr1(0, 0, 0); /* if(n1 <= n0 && n1 <= nw0t) { ans = 0; recurr1(0, 0, 0); } else if(nw0t <= n0 && nw0t <= n1) { ans = 0; recurrw0t(0, 0); } else { }*/ cout << ans << endl; } } }
#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...