結果

問題 No.1245 ANDORゲーム(calc)
ユーザー CELICACELICA
提出日時 2020-10-04 09:41:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 171,432 KB
実行使用メモリ 7,288 KB
最終ジャッジ日時 2023-09-26 10:54:05
合計ジャッジ時間 8,396 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 79 ms
7,112 KB
testcase_12 AC 78 ms
7,168 KB
testcase_13 AC 79 ms
7,288 KB
testcase_14 AC 78 ms
7,004 KB
testcase_15 AC 78 ms
7,104 KB
testcase_16 AC 79 ms
7,028 KB
testcase_17 AC 71 ms
7,260 KB
testcase_18 AC 68 ms
6,896 KB
testcase_19 AC 65 ms
7,172 KB
testcase_20 AC 74 ms
7,204 KB
testcase_21 AC 71 ms
7,188 KB
testcase_22 AC 67 ms
7,148 KB
testcase_23 AC 79 ms
6,904 KB
testcase_24 AC 78 ms
6,864 KB
testcase_25 AC 42 ms
4,468 KB
testcase_26 AC 45 ms
6,212 KB
testcase_27 AC 53 ms
7,276 KB
権限があれば一括ダウンロードができます

ソースコード

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