結果

問題 No.2538 2進元ゲーム
ユーザー ecotteaecottea
提出日時 2023-10-01 19:45:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 2,746 ms
コンパイル使用メモリ 213,772 KB
実行使用メモリ 7,904 KB
最終ジャッジ日時 2023-10-01 19:46:05
合計ジャッジ時間 6,329 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 19 ms
4,380 KB
testcase_31 AC 135 ms
4,380 KB
testcase_32 AC 243 ms
5,796 KB
testcase_33 AC 246 ms
5,784 KB
testcase_34 AC 67 ms
4,376 KB
testcase_35 AC 259 ms
7,904 KB
testcase_36 AC 70 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;


//【最小除外数】O(n log n)
/*
* mex a[0..n) を返す.
*/
int mex(vector<int> a) {
	// 重複除去 & ソート
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());

	// 番兵の追加
	a.push_back(123456789);

	int i = 0;
	while (i == a[i]) i++;

	return i;
}


int main() {
	// nimber のメモ用
	unordered_map<long long, int> dp;
	dp[0] = 0;

	// 数 a の nimber を返す.
	function<int(long long)> get_nimber = [&](long long a) {
		// ω を 2^10 で代用する.
		if (a < 0) return 1 << 10;

		if (dp.count(a)) return dp[a];

		vector<int> na;
		for (int b = 0; b < 64; b++) {
			if (a & (1LL << b)) {
				na.push_back(get_nimber(b));
			}
		}

		return dp[a] = mex(na);
	};

	int n;
	cin >> n;

	int nimber = 0;

	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;

		nimber ^= get_nimber(a);
	}

	cout << (nimber == 0 ? 2 : 1) << endl;
}
0