結果
問題 |
No.1245 ANDORゲーム(calc)
|
ユーザー |
|
提出日時 | 2020-10-06 16:43:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 857 bytes |
コンパイル時間 | 1,838 ms |
コンパイル使用メモリ | 196,896 KB |
最終ジャッジ日時 | 2025-01-15 03:02:00 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); REP (i, n) cin >> a[i]; string s; cin >> s; long long dp[30][2]; REP (i, 30) { REP (j, 2) { dp[i][j] = 0; int t = (1<<i) * j; REP (k, n) { int w = (s[k] == '0') ? (t & a[k]) : (t | a[k]); w &= 1<<i; dp[i][j] += abs(w - t); t = w; } } } REP (i, q) { int t; cin >> t; long long ret = 0; REP (j, 30) { if (t & 1<<j) ret += dp[j][1]; else ret += dp[j][0]; } cout << ret << endl; } return 0; }