結果
問題 |
No.1245 ANDORゲーム(calc)
|
ユーザー |
|
提出日時 | 2020-10-17 18:32:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 351 ms / 2,000 ms |
コード長 | 1,578 bytes |
コンパイル時間 | 2,082 ms |
コンパイル使用メモリ | 197,756 KB |
最終ジャッジ日時 | 2025-01-15 11:01:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i)) #define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i)) #define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i)) #define ALL(x) ::std::begin(x), ::std::end(x) using namespace std; int64_t solve1(int n, const vector<int64_t>& a, string s, int k, int64_t t) { int64_t ans = 0; int64_t x = t; REP (i, n) { int64_t nx; if (s[i] == '0') { nx = x & a[i]; } else if (s[i] == '1') { nx = x | a[i]; } else { assert (false); } nx &= 1ll << k; ans += abs<int64_t>(nx - x); x = nx; } return ans; } vector<int64_t> solve(int n, int q, const vector<int64_t>& a, string s, const vector<int64_t>& t) { array<array<int64_t, 2>, 60> f; REP (i, 60) { f[i][0] = solve1(n, a, s, i, 0); f[i][1] = solve1(n, a, s, i, 1ll << i); } vector<int64_t> ans(q); REP (j, q) { REP (i, 60) { ans[j] += f[i][not not (t[j] & (1ll << i))]; } } return ans; } // generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) int main() { int N, Q; cin >> N >> Q; vector<int64_t> A(N); REP (i, N) { cin >> A[i]; } string S; cin >> S; vector<int64_t> t(Q); REP (i, Q) { cin >> t[i]; } auto ans = solve(N, Q, A, S, t); REP (i, Q) { cout << ans[i] << endl; } return 0; }