結果

問題 No.153 石の山
ユーザー はまやんはまやん
提出日時 2017-02-22 15:24:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 638 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 171,092 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 18:42:59
合計ジャッジ時間 3,070 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




int N;
//-----------------------------------------------------------------
int grundy(int x) {
	if (x == 1) return 0;
	if (x == 2) return 1;

	int a = grundy(x / 2) ^ grundy(x - x / 2);
	int b = 0;
	if(x % 3 == 2)
		b = grundy(x / 3) ^ grundy(x / 3 + 1) ^ grundy(x / 3 + 1);
	else
		b = grundy(x / 3) ^ grundy(x / 3) ^ grundy(x - 2 * x / 3);
	set<int> s;
	s.insert(a); s.insert(b);

	int ret = 0;
	for (int i : s) if (ret == i) ret++;
	return ret;
}
int main() {
	cin >> N;

	int g = grundy(N);
	if (g != 0)
		printf("A\n");
	else
		printf("B\n");
}
0