結果

問題 No.715 集合と二人ゲーム
ユーザー ats5515ats5515
提出日時 2017-09-12 00:16:14
言語 C++11
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,194 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-11-17 09:23:20
合計ジャッジ時間 51,544 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45 TLE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
signed main() {

	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int seq = 1;
	int maxseq = 1;

	vector<int> cnt;
	for (int i = 0; i < N - 1; i++) {
		if (a[i] + 1 == a[i + 1]) {
			seq++;
		}
		else {
			cnt.push_back(seq);
			maxseq = max(maxseq, seq);
			seq = 1;
		}
	}
	cnt.push_back(seq);
	maxseq = max(maxseq, seq);
	int Nmax = maxseq;
	vector<int>G(Nmax + 1);
	G[0] = 0;
	G[1] = 1;
	G[2] = 1;
	set<int> st;
	int t = 0;
	for (int i = 3; i <= Nmax; i++) {
		st.clear();
		st.insert(G[i - 2]);
		st.insert(G[i - 3]);
		for (int j = 0; i - 4 - j > 0; j++) {
			st.insert(G[i - 4 - j] ^ G[j + 1]);
		}
		t = 0;
		G[i] = -1;
		for (auto s : st) {
			if (t != s) {
				G[i] = t;
				break;
			}
			t++;
		}
		if (G[i] == -1) G[i] = t;
	}
	int Grundy = 0;
	for (int i = 0; i < cnt.size(); i++) {
		Grundy ^= G[cnt[i]];
	}
	if (Grundy > 0) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	return 0;
}
0