結果

問題 No.7 プライムナンバーゲーム
ユーザー ssmkzkssmkzk
提出日時 2018-10-23 23:32:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-29 21:12:25
合計ジャッジ時間 6,108 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,752 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 774 ms
11,264 KB
testcase_03 AC 75 ms
10,880 KB
testcase_04 AC 39 ms
10,752 KB
testcase_05 AC 39 ms
10,752 KB
testcase_06 AC 237 ms
11,008 KB
testcase_07 AC 171 ms
10,880 KB
testcase_08 AC 92 ms
10,880 KB
testcase_09 AC 354 ms
11,008 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 174 ms
11,008 KB
testcase_12 WA -
testcase_13 AC 565 ms
11,264 KB
testcase_14 AC 729 ms
11,136 KB
testcase_15 AC 704 ms
11,136 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def SoE(x):
    if x < 2:
        return []
    
    l = [i for i in range(x + 1)]
    l[1] = 0
    
    for i in l:
        if i > math.sqrt(x):
            break
        if i == 0:
            continue
        for j in range(2 * i , x + 1, i):
            l[j] = 0
    
    return [i for i in l if i != 0]

N = int(input())
l_prime = SoE(N)

dp = [-1 for i in range(N + 1)]
dp[2] = 0
dp[3] = 0

for i in range(N + 1):
    for prime in l_prime:
        if i - prime < 2:
            dp[i] = 0
            break
        if i - prime <= 3 or dp[i - prime] == 0:
            dp[i] = 1
            break
    else:
        dp[-1] = 0


if dp[-1]:
    print("Win")
else:
    print("Lose")


        
0