結果

問題 No.8 N言っちゃダメゲーム
コンテスト
ユーザー koyumeishi
提出日時 2015-01-08 01:53:15
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,108 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 784 ms
コンパイル使用メモリ 100,656 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2026-03-05 22:19:18
合計ジャッジ時間 44,442 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int grundy(int)':
main.cpp:22:24: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   22 |                 memo.at(x);
      |                 ~~~~~~~^~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:68,
                 from main.cpp:2:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:1313:7: note: declared here
 1313 |       at(size_type __n)
      |       ^~
main.cpp:42:24: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   42 |                 memo.at(x);
      |                 ~~~~~~~^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:1313:7: note: declared here
 1313 |       at(size_type __n)
      |       ^~

ソースコード

diff #
raw source code

#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