제출 #330399

#제출 시각아이디문제언어결과실행 시간메모리
330399casperwangSnake Escaping (JOI18_snake_escaping)C++14
100 / 100
1139 ms29232 KiB
#include <bits/stdc++.h> using namespace std; const int MAXL = 20; const int MAXQ = 1000000; int L, Q; string str; int val[1<<MAXL]; int sum0[1<<MAXL]; int sum1[1<<MAXL]; int cnt[1<<MAXL]; int p0, p1, pq; int ans; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> L >> Q; cin >> str; for (int i = 0; i < (1<<L); i++) { val[i] = sum0[i] = sum1[i] = str[i] - '0'; cnt[i] = cnt[i>>1] + (i&1); } for (int i = 0; i < L; i++) { for (int j = 0; j < (1<<L); j++) { if ((1<<i) & j) { sum0[j] += sum0[(1<<i) ^ j]; sum1[(1<<i) ^ j] += sum1[j]; } } } for (int i = 0; i < Q; i++) { cin >> str; p0 = p1 = pq = 0; for (int j = 0; j < L; j++) { if (str[L-1-j] == '0') p0 |= (1<<j); if (str[L-1-j] == '1') p1 |= (1<<j); if (str[L-1-j] == '?') pq |= (1<<j); } ans = 0; if (cnt[p0] <= 6) { for (int j = p0; ; j=(j-1)&p0) { if (cnt[j] & 1) ans -= sum1[p1 | j]; else ans += sum1[p1 | j]; if (!j) break; } } else if (cnt[p1] <= 6) { for (int j = p1; ; j=(j-1)&p1) { if (cnt[p1 ^ j] & 1) ans -= sum0[pq | j]; else ans += sum0[pq | j]; if (!j) break; } } else { for (int j = pq; ; j=(j-1)&pq) { ans += val[p1 | j]; if (!j) 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...