結果

問題 No.2538 2進元ゲーム
ユーザー ecottea
提出日時 2023-10-01 19:45:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 208,140 KB
最終ジャッジ日時 2025-02-17 03:57:47
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

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