제출 #873636

#제출 시각아이디문제언어결과실행 시간메모리
873636tvladm2009Snake Escaping (JOI18_snake_escaping)C++17
0 / 100
1 ms4572 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int L = 21; const int M = (1 << L) + 7; const int K = 6; int m; int l; int q; string s; int a[M]; int f[M]; int g[M]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> l >> q >> s; m = (1 << l); for (int i = 0; i < m; ++i) { a[i] = s[i] - '0'; } for (int i = 0; i < m; ++i) { f[i] = a[i]; g[i] = a[i]; } for (int j = 0; j < l; ++j) { for (int i = 0; i < m; ++i) { if ((i >> j) & 1) { f[i] += f[i ^ (1 << j)]; g[i ^ (1 << j)] += g[i]; } } } while (q--) { vector<int> t(3, 0); string tt; cin >> tt; for (int i = l - 1; i >= 0; --i) { t[tt[i] == '?' ? 2 : tt[i] - '0'] |= (1 << (l - i - 1)); } if (__builtin_popcount(t[1]) <= K) { int ans = 0; int ppc = __builtin_popcount(t[1]); for (int z = t[1]; ; z = (z - 1) & t[1]) { ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[2] | z]; if (z == 0) { break; } } cout << ans << "\n"; } else if (__builtin_popcount(t[0]) <= K) { int ans = 0; int ppc = __builtin_popcount(t[0]); for (int z = t[0]; ; z = (z - 1) & t[0]) { ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[0] ^ t[1] ^ z]; if (z == 0) { break; } } cout << ans << "\n"; } else { assert(__builtin_popcount(t[2]) <= K); int ans = 0; for (int z = t[2]; ; z = (z - 1) & t[2]) { ans += a[t[1] | z]; if (z == 0) { break; } } cout << ans << "\n"; } } return 0; }
#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...