結果

問題 No.7 プライムナンバーゲーム
ユーザー togatogatogatoga
提出日時 2015-08-15 07:47:31
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,899 ms / 5,000 ms
コード長 622 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 76,948 KB
実行使用メモリ 86,868 KB
最終ジャッジ日時 2024-04-09 03:49:35
合計ジャッジ時間 14,038 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
77,952 KB
testcase_01 AC 77 ms
78,124 KB
testcase_02 AC 1,899 ms
84,920 KB
testcase_03 AC 133 ms
79,144 KB
testcase_04 AC 97 ms
78,632 KB
testcase_05 AC 98 ms
78,584 KB
testcase_06 AC 490 ms
81,468 KB
testcase_07 AC 302 ms
80,916 KB
testcase_08 AC 118 ms
78,876 KB
testcase_09 AC 727 ms
82,744 KB
testcase_10 AC 77 ms
77,624 KB
testcase_11 AC 302 ms
81,044 KB
testcase_12 AC 1,266 ms
84,116 KB
testcase_13 AC 1,368 ms
84,116 KB
testcase_14 AC 1,861 ms
85,264 KB
testcase_15 AC 1,755 ms
86,868 KB
testcase_16 AC 1,595 ms
85,052 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