結果

問題 No.7 プライムナンバーゲーム
ユーザー AT274_AT274_
提出日時 2019-11-01 22:23:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 662 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 04:45:08
合計ジャッジ時間 5,641 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 660 ms
11,008 KB
testcase_03 AC 73 ms
10,880 KB
testcase_04 AC 41 ms
10,880 KB
testcase_05 AC 40 ms
11,008 KB
testcase_06 AC 212 ms
10,752 KB
testcase_07 AC 157 ms
10,880 KB
testcase_08 AC 85 ms
10,880 KB
testcase_09 AC 303 ms
10,880 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 153 ms
10,880 KB
testcase_12 AC 495 ms
11,008 KB
testcase_13 AC 517 ms
10,880 KB
testcase_14 AC 662 ms
11,008 KB
testcase_15 AC 633 ms
11,008 KB
testcase_16 AC 563 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())


def eratosthenes_sieve(n):
    if n < 2:
        return []

    is_primes = [True] * (n + 1)
    for x in range(2, int(n ** 0.5 + 1) + 1):
        if is_primes[x]:
            for mx in range(2 * x, n + 1, x):
                is_primes[mx] = False

    return [i for i in range(2, n + 1) if is_primes[i]]


primes = eratosthenes_sieve(N)
# dp[i] := 残りiで先手に回ってきたとき先手が勝ちか負けか
dp = [''] * (N + 1)
dp[0] = 'W'
dp[1] = 'W'

for i in range(2, N + 1):
    for p in primes:
        if i - p < 0:
            continue

        if dp[i - p] == 'L':
            dp[i] = 'W'
            break

    else:
        dp[i] = 'L'

print('Win' if dp[N] == 'W' else 'Lose')
0