結果

問題 No.7 プライムナンバーゲーム
ユーザー こるこる
提出日時 2017-01-05 09:39:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,036 ms / 5,000 ms
コード長 391 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 04:10:46
合計ジャッジ時間 20,475 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 3,036 ms
11,136 KB
testcase_03 AC 203 ms
10,752 KB
testcase_04 AC 73 ms
10,752 KB
testcase_05 AC 70 ms
10,880 KB
testcase_06 AC 841 ms
11,136 KB
testcase_07 AC 554 ms
11,008 KB
testcase_08 AC 259 ms
10,880 KB
testcase_09 AC 1,239 ms
11,008 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 555 ms
10,880 KB
testcase_12 AC 2,100 ms
11,136 KB
testcase_13 AC 2,178 ms
11,136 KB
testcase_14 AC 2,903 ms
11,136 KB
testcase_15 AC 2,768 ms
11,136 KB
testcase_16 AC 2,441 ms
11,136 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