結果

問題 No.7 プライムナンバーゲーム
ユーザー netyo715netyo715
提出日時 2021-06-21 11:21:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 532 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 11,256 KB
最終ジャッジ日時 2023-09-05 01:50:28
合計ジャッジ時間 32,691 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,876 KB
testcase_01 AC 17 ms
7,920 KB
testcase_02 AC 4,790 ms
11,256 KB
testcase_03 AC 272 ms
9,012 KB
testcase_04 AC 83 ms
8,476 KB
testcase_05 AC 79 ms
8,592 KB
testcase_06 AC 1,237 ms
10,056 KB
testcase_07 AC 961 ms
9,292 KB
testcase_08 AC 376 ms
8,936 KB
testcase_09 AC 1,940 ms
10,220 KB
testcase_10 AC 16 ms
7,904 KB
testcase_11 AC 973 ms
9,428 KB
testcase_12 AC 3,347 ms
10,736 KB
testcase_13 WA -
testcase_14 AC 4,790 ms
11,168 KB
testcase_15 AC 4,576 ms
11,052 KB
testcase_16 AC 4,200 ms
11,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())

hurui = set(range(2, N+1))
for i in range(2, N+1):
    for j in range(i*2, N+1, i):
        hurui.discard(j)

dp = [-1]*(N+10)
dp[0] = 0
dp[1] = 0
def grundy(x):
    if dp[x] != -1:
        return dp[x]
    s = set()
    for i in range(2, x+1):
        if i in hurui:
            s.add(grundy(x-i))
    for i in range(x+1):
        if i not in s:
            dp[x] = i
            return i

if grundy(N)&1:
    print("Lose")
else:
    print("Win")
0