結果

問題 No.8 N言っちゃダメゲーム
ユーザー koyumeishikoyumeishi
提出日時 2015-01-08 01:53:15
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 75,412 KB
実行使用メモリ 13,996 KB
最終ジャッジ日時 2023-09-03 22:20:11
合計ジャッジ時間 7,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>
#include "assert.h"
#include <ctime>
#include <stdexcept>

using namespace std;

int N,K;
vector<int> memo;

int grundy(int x){
	try{
		memo.at(x);
	}catch(const out_of_range& err){
		cout << "here " << x << endl;
	}
	
	if(memo.at(x)>=0){
		return memo.at(x);
	}
	//cerr << "grundy " << x << endl;

	int ret = 0;
	for(int i=1; i<=K; i++){
		if(x+i >= N) break;
		if(grundy(x+i) == 0){
			ret = 1;
			break;
		}
	}
	
	try{
		memo.at(x);
	}catch(const out_of_range& err){
		cout << "here_ " << x << endl;
	}
	
	memo.at(x) = ret;
	return ret;
}

void solve(){
	cin >> N >> K;
	memo = vector<int>(120000+1, -1);
	int ans = grundy(0);
	/*
	for(int i=0; i<=N; i++){
		cerr << i << " " << memo[i] << endl;
	}
	*/
	cout << (ans!=0? "Win":"Lose") << endl;
}

int main(){
	//clock_t start,end;
	//start = clock();
	
	int T;
	cin >> T;
	for(int i=0; i<T; i++){
		solve();
	}

	//end = clock();
	//printf("%d\n", (int)end-start);
	return 0;
}
0