結果

問題 No.7 プライムナンバーゲーム
ユーザー togatogatogatoga
提出日時 2015-08-15 07:55:34
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 564 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 77,116 KB
実行使用メモリ 85,940 KB
最終ジャッジ日時 2024-04-09 03:48:37
合計ジャッジ時間 5,631 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
77,884 KB
testcase_01 AC 79 ms
78,100 KB
testcase_02 AC 561 ms
85,940 KB
testcase_03 AC 94 ms
79,164 KB
testcase_04 AC 87 ms
78,788 KB
testcase_05 AC 88 ms
78,744 KB
testcase_06 AC 180 ms
81,032 KB
testcase_07 AC 143 ms
80,156 KB
testcase_08 AC 97 ms
79,368 KB
testcase_09 AC 250 ms
81,944 KB
testcase_10 AC 81 ms
78,140 KB
testcase_11 AC 144 ms
80,416 KB
testcase_12 AC 400 ms
83,072 KB
testcase_13 AC 427 ms
83,576 KB
testcase_14 AC 564 ms
83,896 KB
testcase_15 AC 528 ms
83,644 KB
testcase_16 AC 492 ms
83,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import time
sys.setrecursionlimit(1 << 30)
N = input()
dp = [-1 for i in range(10010)]
prime = [True for i in range(10010)]
p = []
def sieve():
    prime[0] = False
    prime[1] = False
    for i in range(2, 10001):
        if (prime[i]):
            p.append(i)
            for j in range(i * i, 10001, 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 p:
        if (i > pos):
            break
        win |= not memo(pos - i)
        if (win):
            break
    dp[pos] = win
    return win

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