結果

問題 No.7 プライムナンバーゲーム
ユーザー hiro1729hiro1729
提出日時 2023-07-28 13:31:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 488 ms / 5,000 ms
コード長 492 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-15 22:06:17
合計ジャッジ時間 4,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
10,752 KB
testcase_01 AC 36 ms
10,752 KB
testcase_02 AC 439 ms
10,880 KB
testcase_03 AC 62 ms
10,880 KB
testcase_04 AC 42 ms
10,624 KB
testcase_05 AC 41 ms
10,752 KB
testcase_06 AC 153 ms
10,496 KB
testcase_07 AC 117 ms
10,624 KB
testcase_08 AC 68 ms
10,752 KB
testcase_09 AC 217 ms
10,624 KB
testcase_10 AC 33 ms
10,624 KB
testcase_11 AC 117 ms
10,752 KB
testcase_12 AC 339 ms
10,624 KB
testcase_13 AC 364 ms
10,880 KB
testcase_14 AC 488 ms
10,752 KB
testcase_15 AC 430 ms
10,752 KB
testcase_16 AC 457 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
def EraSieve(n: int) -> list:
    r = [True] * (n + 1)
    r[0] = r[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if r[i]:
            for j in range(2 * i, n + 1, i):
                r[j] = False
    return r
p = [i for i, j in enumerate(EraSieve(n)) if j]
dp = [-1 for _ in range(n + 1)]
dp[0] = 1
dp[1] = 1
for i in range(2, n + 1):
	k = 0
	for j in p:
		if j > i:
			break
		if dp[i - j] == 0:
			k = 1
			break
	dp[i] = k
print("Win" if dp[n] else "Lose")
0