結果

問題 No.7 プライムナンバーゲーム
ユーザー togatogatogatoga
提出日時 2015-08-15 07:55:06
言語 Python2
(2.7.18)
結果
AC  
実行時間 669 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 03:49:07
合計ジャッジ時間 5,556 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,168 KB
testcase_01 AC 16 ms
7,168 KB
testcase_02 AC 669 ms
11,136 KB
testcase_03 AC 58 ms
7,936 KB
testcase_04 AC 27 ms
7,424 KB
testcase_05 AC 27 ms
7,424 KB
testcase_06 AC 207 ms
9,088 KB
testcase_07 AC 146 ms
8,704 KB
testcase_08 AC 73 ms
8,064 KB
testcase_09 AC 307 ms
9,600 KB
testcase_10 AC 16 ms
7,040 KB
testcase_11 AC 148 ms
8,704 KB
testcase_12 AC 482 ms
10,368 KB
testcase_13 AC 521 ms
10,624 KB
testcase_14 AC 666 ms
11,008 KB
testcase_15 AC 631 ms
11,008 KB
testcase_16 AC 585 ms
10,752 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