結果

問題 No.1245 ANDORゲーム(calc)
コンテスト
ユーザー Hydrogen332
提出日時 2025-11-10 22:40:20
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 811 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,991 ms
コンパイル使用メモリ 283,848 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-10 22:40:28
合計ジャッジ時間 7,827 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N, Q;
	cin >> N >> Q;
	vector<ll> A(N);
	rep(i, 0, N) cin >> A[i];
	string S;
	cin >> S;
	
	vector score(2, vector<ll>(32));
	
	rep(bit, 0, 32) {
		vector<int> now = {0, 1};
		vector<ll> res(2, 0);
		rep(i, 0, N) {
			vector<int> nex(2);
			rep(j, 0, 2) {
				if (S[i] == '0') nex[j] = ((A[i] >> bit) & 1) & now[j];
				else nex[j] = ((A[i] >> bit) & 1) | now[j];
				res[j] += abs(now[j] - nex[j]);
				now[j] = nex[j];
			}
		}
		rep(j, 0, 2) score[j][bit] = res[j];
	}
	
	for (;Q--;) {
		ll t;
		cin >> t;
		
		ll ans = 0;
		rep(i, 0, 32) ans += score[(t >> i) & 1][i] << i;
		cout << ans << '\n';
	}
}
0