結果

問題 No.8 N言っちゃダメゲーム
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-04-20 20:35:30
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 925 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 70,224 KB
実行使用メモリ 10,784 KB
最終ジャッジ日時 2024-04-15 03:55:09
合計ジャッジ時間 6,973 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <vector>


constexpr int UNDEF = -1;


// Based on http://solorab.net/blog/2015/12/19/srm-676-med/
int mex(std::set<int> const& s) {
	int m = 0;
	for (auto x : s)
	{
		if (x == m)
		{
			m++;
		}
		else
		{
			break;
		}
	}
	return m;
}


int compute_grundy_number(int n, int k) {
	std::vector<int> gs;
	gs = std::vector<int>(n, UNDEF);
	gs[n - 1] = 0;
	for (auto i = n - 2; i >= 0; i--)
	{
		std::set<int> next_gs;
		for (auto j = i + 1; j <= std::min(n - 1, i + k); j++)
		{
			next_gs.insert(gs[j]);
		}
		gs[i] = mex(next_gs);
	}
	return gs[0];
}


int main() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	int p;
	std::cin >> p;
	for (auto i = 0; i < p; i++)
	{
		int n, k;
		std::cin >> n >> k;
		int g;
		g = compute_grundy_number(n, k);
		std::cout << (g != 0 ? "Win" : "Lose") << std::endl;
	}
	return EXIT_SUCCESS;
}
0