結果

問題 No.1245 ANDORゲーム(calc)
ユーザー CELICA
提出日時 2020-10-04 09:41:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 173,712 KB
実行使用メモリ 7,236 KB
最終ジャッジ日時 2024-07-19 05:36:34
合計ジャッジ時間 6,375 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, q;
	cin >> n >> q;

	vector< vector<ll> > score(2, vector<ll>(30, 0));

	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	string s;
	cin >> s;
	for (int i = 0; i < 2; ++i)
	{
		bitset<30> cv(0UL);
		if (i == 1)
		{
			for (int j = 0; j < 30; ++j)
				cv.set(j);
		}
		for (int j = 0; j < 30; ++j)
		{
			for (int k = 0; k < n; ++k)
			{
				ll bit = (a[k] >> j) & 1LL, nxt;
				if (s[k] == '0')
					nxt = cv[j] & bit;
				else
					nxt = cv[j] | bit;

				score[i][j] += (cv[j] ^ nxt) << j;
				cv[j] = nxt;
			}
		}
	}

	stringstream ss;
	for (int i = 0; i < q; ++i)
	{
		ll t;
		cin >> t;

		ll ans{ 0 };
		for (int i = 0; i < 30; ++i)
			ans += score[(t >> i) & 1][i];

		ss << ans << "\n";
	}

	cout << ss.str();

	return 0;
}
0