제출 #1127082

#제출 시각아이디문제언어결과실행 시간메모리
1127082GasmaskChanSnake Escaping (JOI18_snake_escaping)C++17
0 / 100
8 ms320 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int MAX = 1e6 + 5; int a[1 << 20], f1[1 << 20], f2[1 << 20]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); int n, q; cin >> n >> q; string s; cin >> s; for (int i = 0; i < (1 << n); i++) { a[i] = s[i] - '0'; f1[i] = f2[i] = a[i]; } for (int i = 0; i < n; i++) { for (int mask = 0; mask < (1 << n); mask++) { if (mask >> i & 1) { f1[mask] += f1[mask ^ (1 << i)]; } else { f2[mask] += f2[mask ^ (1 << i)]; } } } while (q--) { cin >> s; int cntA = 0, cntB = 0, cntC = 0; int A = 0, B = 0, C = 0; for (int i = 0; i < n; i++) { if (s[i] == '0') ++cntA, A |= (1 << i); else if (s[i] == '1') ++cntB, B |= (1 << i); else ++cntC, C |= (1 << i); } cerr << bitset<3>(A) << ' ' << bitset<3>(B) << ' ' << bitset<3>(C) << '\n'; int ans = 0; if (cntA < 7) { for (int mask = A; mask >= 0; mask--) { mask &= A; if (__builtin_popcount(mask) & 1) ans -= f2[mask | B]; else ans += f2[mask | B]; } } else if (cntB < 7) { for (int mask = B; mask >= 0; mask--) { mask &= B; if ((__builtin_popcount(B) - __builtin_popcount(mask)) & 1) ans -= f1[C | mask]; else ans += f1[C | mask]; } } else { for (int mask = C; mask >= 0; mask--) { mask &= C; ans += a[mask | B]; } } 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...