結果

問題 No.153 石の山
ユーザー koyumeishi
提出日時 2015-02-15 23:36:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 616 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 78,600 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 14:17:01
合計ジャッジ時間 1,659 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int grundy(int x){
	if(x==0) return 0;

	set<int> s;

	if(x/3>0){
		int a = x/3;
		int b = (x-a)/2;
		int c = x-a-b;

		s.insert( grundy(a) ^ grundy(b) ^ grundy(c) );
	}

	if(x/2 > 0){
		int a = x/2;
		int b = x-a;

		s.insert( grundy(a) ^ grundy(b) );
	}

	int g = 0;
	while(s.count(g) != 0) g++;
	return g;
}

int main(){
	int N;
	cin >> N;
	
	int ans = grundy(N);

	cout << (ans==0?"B":"A") << endl;

	return 0;
}
0