結果

問題 No.7 プライムナンバーゲーム
ユーザー gorugo30gorugo30
提出日時 2021-02-25 21:31:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,555 ms / 5,000 ms
コード長 536 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-09 05:03:50
合計ジャッジ時間 11,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
10,880 KB
testcase_01 AC 41 ms
10,880 KB
testcase_02 AC 1,555 ms
11,904 KB
testcase_03 AC 131 ms
11,008 KB
testcase_04 AC 62 ms
10,880 KB
testcase_05 AC 62 ms
10,880 KB
testcase_06 AC 471 ms
11,520 KB
testcase_07 AC 327 ms
11,264 KB
testcase_08 AC 166 ms
11,008 KB
testcase_09 AC 701 ms
11,776 KB
testcase_10 AC 39 ms
10,752 KB
testcase_11 AC 331 ms
11,264 KB
testcase_12 AC 1,115 ms
11,776 KB
testcase_13 AC 1,191 ms
11,904 KB
testcase_14 AC 1,541 ms
11,904 KB
testcase_15 AC 1,464 ms
11,904 KB
testcase_16 AC 1,348 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
def isp(x):
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True
P = []
for i in range(2, 10001):
    if isp(i):
        P.append(i)
def canwin(x):
    if x <= 1:
        return 1
    if dp[x] != -1:
        return dp[x]
    ans = 0
    for p in P:
        if p > x:
            break
        ans |= canwin(x - p) ^ 1
    dp[x] = ans
    return ans

N = int(input())
dp = [-1] * (N + 1)
if canwin(N):
    print("Win")
else:
    print("Lose")
0