結果
問題 |
No.1245 ANDORゲーム(calc)
|
ユーザー |
![]() |
提出日時 | 2020-10-03 00:33:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 281 ms / 2,000 ms |
コード長 | 952 bytes |
コンパイル時間 | 2,035 ms |
コンパイル使用メモリ | 199,280 KB |
最終ジャッジ日時 | 2025-01-15 01:31:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair<int,int> P; int main() { int n, q; cin >> n >> q; vector<int> a(n); rep(i,n) cin >> a[i]; string s; cin >> s; vector<vector<ll>> dp(2, vector<ll>(31, 0)); for (int i = 0; i < 2; i++) { for (int j = 0; j < 31; j++) { int cur = i; for (int k = 0; k < n; k++) { int next = cur; if (s[k] == '1') next |= ((a[k] & (1 << j)) >> j); else next &= ((a[k] & (1 << j)) >> j); dp[i][j] += abs(cur - next) * (1 << j); cur = next; } } } while (q--) { int a; cin >> a; ll res = 0; for (int i = 0; i < 31; i++) { if (a & (1 << i)) res += dp[1][i]; else res += dp[0][i]; } cout << res << endl; } return 0; }