結果

問題 No.361 門松ゲーム2
ユーザー koyumeishikoyumeishi
提出日時 2016-03-24 12:35:22
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 69,360 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-02 00:08:59
合計ジャッジ時間 2,016 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
#include <cassert>
using namespace std;

vector<int> memo;
int d;

int grundy(int L){
	if(memo[L] != -1) return memo[L];

	int ret;
	set<int> s;
	for(int a=1; a<L; a++){
		for(int b=a+1; a+b<L; b++){
			int c = L-(a+b);
			if(c<=b) break;
			if(a<b && b<c && c-a<=d){
				s.insert( grundy(a) ^ grundy(b) ^ grundy(c) );
			}
		}
	}
	ret = 0;
	while(s.count(ret)) ret++;

	return memo[L] = ret;
}

int main(){
	int L;
	cin >> L >> d;
	assert(1<=d && d<=L && L<=500);

	memo.resize(L+1, -1);
	int ans = grundy(L);
	cout << (ans!=0?"kado":"matsu") << endl;

	return 0;
}
0