結果

問題 No.8 N言っちゃダメゲーム
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-04-20 19:09:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 715 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-15 03:54:30
合計ジャッジ時間 933 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools
import itertools


def mex(s):
    if not s:
        return 0
    else:
        for i in itertools.count():
            if i not in s:
                return i


def can_i_win(n, k):
    @functools.lru_cache()
    def compute_grundy_number(current_number):
        new_numbers = range(current_number + 1, min(n, current_number + k + 1))
        gs = set(map(compute_grundy_number, new_numbers))
        return mex(gs)
    return compute_grundy_number(0) != 0


def main():
    p = int(input())
    for _ in range(p):
        n, k = map(int, input().split())
        print("Win" if can_i_win(n, k) else "Lose")


if __name__ == '__main__':
    main()
0