結果

問題 No.7 プライムナンバーゲーム
ユーザー cleanttedcleantted
提出日時 2016-10-09 01:45:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,861 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 04:04:16
合計ジャッジ時間 13,374 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 1,788 ms
10,880 KB
testcase_03 AC 134 ms
10,752 KB
testcase_04 AC 56 ms
10,752 KB
testcase_05 AC 55 ms
10,752 KB
testcase_06 AC 525 ms
10,880 KB
testcase_07 AC 360 ms
10,752 KB
testcase_08 AC 177 ms
10,752 KB
testcase_09 AC 797 ms
10,752 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 366 ms
10,752 KB
testcase_12 AC 1,268 ms
10,880 KB
testcase_13 AC 1,370 ms
10,880 KB
testcase_14 AC 1,861 ms
11,008 KB
testcase_15 AC 1,692 ms
11,008 KB
testcase_16 AC 1,557 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
memo = [-1] * (N+1) #-1 -> (not yet), 0 -> win, 1 -> Lose
prime = []

memo[0] = 0    #0 -> win
memo[1] = 0    #0 -> win

#素数列を作る(=prime)
for n in range(2,N+1):
    flag = True
    for m in range(2, n):
        if n%m == 0:
            flag = False
            break
    if flag: prime.append(n)

def res(i):
    if memo[i] != -1: return(memo[i])   #計算済なら、それを返す
    else:
        flag = 1
        for p in prime:
            if p < i: flag = flag * (1 - res(i-p))
            else: break
        memo[i] = flag                      #計算結果をmemoに入れる
        return(flag)

for i in range(N):
    res(i)

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