結果

問題 No.7 プライムナンバーゲーム
ユーザー 8080
提出日時 2018-09-05 23:54:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 680 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-27 15:15:41
合計ジャッジ時間 1,366 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# -*- coding: utf-8 -*-
N = int(input())
isPrime = [True] * (N + 1)

#エラトステネスの篩
for i in range(2,N + 1) :
    if isPrime[i]:
        for j in range(2 * i,N + 1,i):
            isPrime[j]=False
            
dp = [-1] * (N + 1)
def grundy(x):
    #計算済みの場合
    if dp[x] == 0 :
        return dp[x]
    #2、または3を渡されたら負け
    if x == 2 or x == 3:
        dp[x] = 0
        return dp[x]
    
    lst = []
    for i in range(2,x+1):
        
        if isPrime[i] and x-i >= 2:
            lst.append(grundy(x-i))
        
    dp[x] = sum(lst)
    return dp[x]

res = grundy(N)
if res==0:
    print("Lose")
else:
    print("Win")



0