結果

問題 No.7 プライムナンバーゲーム
ユーザー こるこる
提出日時 2017-01-05 09:39:56
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 2,513 ms / 5,000 ms
コード長 391 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,632 KB
最終ジャッジ日時 2023-07-24 20:47:21
合計ジャッジ時間 17,077 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,852 KB
testcase_01 AC 14 ms
7,848 KB
testcase_02 AC 2,513 ms
8,508 KB
testcase_03 AC 162 ms
7,840 KB
testcase_04 AC 51 ms
7,844 KB
testcase_05 AC 47 ms
7,800 KB
testcase_06 AC 693 ms
8,408 KB
testcase_07 AC 494 ms
8,360 KB
testcase_08 AC 224 ms
8,388 KB
testcase_09 AC 1,072 ms
8,472 KB
testcase_10 AC 13 ms
7,792 KB
testcase_11 AC 469 ms
8,312 KB
testcase_12 AC 1,705 ms
8,464 KB
testcase_13 AC 1,835 ms
8,504 KB
testcase_14 AC 2,393 ms
8,632 KB
testcase_15 AC 2,292 ms
8,524 KB
testcase_16 AC 2,140 ms
8,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=list(range(n+1))
a[1]=0
i=2
while i**2<=n:
    j=2
    while i*j<=n:
        a[i*j]=0
        j+=1
    i+=1
list=[]
for i in a:
    if i>0:
        list.append(i)

dp=[-1]*(n+1)
dp[0]=0
dp[1]=0

for i in range(2,n+1):
    s=0
    p=0
    while p<len(list) and list[p] <= i:
        s+=dp[i-list[p]]
        p+=1
    dp[i]=0 if s>0 else 1
print("Win" if dp[n]==0 else "Lose")
0