結果

問題 No.7 プライムナンバーゲーム
ユーザー togatogatogatoga
提出日時 2015-08-15 07:47:31
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 1,968 ms / 5,000 ms
コード長 622 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 77,604 KB
実行使用メモリ 88,480 KB
最終ジャッジ日時 2023-07-24 20:25:07
合計ジャッジ時間 14,098 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
79,044 KB
testcase_01 AC 82 ms
78,764 KB
testcase_02 AC 1,966 ms
88,480 KB
testcase_03 AC 138 ms
80,392 KB
testcase_04 AC 102 ms
79,896 KB
testcase_05 AC 101 ms
79,992 KB
testcase_06 AC 485 ms
83,628 KB
testcase_07 AC 338 ms
83,008 KB
testcase_08 AC 122 ms
80,496 KB
testcase_09 AC 790 ms
84,896 KB
testcase_10 AC 82 ms
78,836 KB
testcase_11 AC 335 ms
84,760 KB
testcase_12 AC 1,320 ms
87,248 KB
testcase_13 AC 1,418 ms
86,224 KB
testcase_14 AC 1,968 ms
87,004 KB
testcase_15 AC 1,838 ms
86,780 KB
testcase_16 AC 1,678 ms
86,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1 << 30)
N = input()
dp = [-1 for i in range(10010)]
prime = [True for i in range(10010)]
def sieve():
    prime[0] = False
    prime[1] = False
    for i in range(2, 10010):
        if (prime[i]):
            for j in range(i * i, 10010, i):
                prime[j] = False


def memo(pos):
    if (pos == 0 or pos == 1):
        return True
    win = False
    if (dp[pos] >= 0):
        return dp[pos]
    for i in range(2, pos):
        if (prime[i]):
            win |= not memo(pos - i)
    dp[pos] = win
    return win

sieve()
if (memo(N)):
    print "Win"
else:
    print "Lose"
0