結果

問題 No.7 プライムナンバーゲーム
ユーザー togatogatogatoga
提出日時 2015-08-25 10:14:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 642 ms / 5,000 ms
コード長 710 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-09 03:50:32
合計ジャッジ時間 5,662 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 33 ms
11,008 KB
testcase_02 AC 642 ms
11,904 KB
testcase_03 AC 72 ms
11,136 KB
testcase_04 AC 43 ms
10,880 KB
testcase_05 AC 42 ms
10,880 KB
testcase_06 AC 215 ms
11,392 KB
testcase_07 AC 151 ms
11,264 KB
testcase_08 AC 83 ms
11,136 KB
testcase_09 AC 309 ms
11,520 KB
testcase_10 AC 33 ms
11,008 KB
testcase_11 AC 154 ms
11,264 KB
testcase_12 AC 474 ms
11,904 KB
testcase_13 AC 492 ms
11,904 KB
testcase_14 AC 616 ms
11,904 KB
testcase_15 AC 597 ms
11,904 KB
testcase_16 AC 563 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import time
sys.setrecursionlimit(1 << 30)
N = eval(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