結果

問題 No.7 プライムナンバーゲーム
ユーザー halshiphalship
提出日時 2021-06-04 20:33:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,139 ms / 5,000 ms
コード長 584 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 05:04:13
合計ジャッジ時間 9,017 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 1,139 ms
11,008 KB
testcase_03 AC 111 ms
10,880 KB
testcase_04 AC 49 ms
10,752 KB
testcase_05 AC 49 ms
10,880 KB
testcase_06 AC 346 ms
10,752 KB
testcase_07 AC 258 ms
10,880 KB
testcase_08 AC 126 ms
10,752 KB
testcase_09 AC 516 ms
10,880 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 241 ms
10,752 KB
testcase_12 AC 806 ms
10,880 KB
testcase_13 AC 879 ms
11,008 KB
testcase_14 AC 1,109 ms
11,008 KB
testcase_15 AC 1,060 ms
11,136 KB
testcase_16 AC 987 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def get_primes(n):
    numbers = [True for _ in range(n + 1)]
    numbers[0] = False
    numbers[1] = False
    result = []

    for i in range(2, n + 1):
        if numbers[i]:
            result.append(i)
            for j in range(i * 2, n + 1, i):
                numbers[j] = False

    return result


n = int(input())
primes = get_primes(n)
dp = [False] * (n + 1)
dp[0] = True
dp[1] = True

for i in range(2, n + 1):
    for x in primes:
        if x > i:
            break
        if not dp[i - x]:
            dp[i] = True

if dp[n]:
    print('Win')
else:
    print('Lose')
0