結果

問題 No.458 異なる素数の和
ユーザー lloyzlloyz
提出日時 2023-10-16 00:02:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 528 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 180,140 KB
最終ジャッジ日時 2023-10-16 00:02:41
合計ジャッジ時間 9,529 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
81,748 KB
testcase_01 AC 1,641 ms
115,436 KB
testcase_02 TLE -
testcase_03 AC 465 ms
83,200 KB
testcase_04 AC 529 ms
84,720 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n = int(input())

IsPrime = [True for _ in range(n + 1)]
IsPrime[0] = IsPrime[1] = False
Primes = []
for i in range(2, n + 1):
    if IsPrime[i]:
        Primes.append(i)
        for j in range(i * i, n + 1, i):
            IsPrime[j] = False
C = defaultdict(lambda: -1)
C[0] = 0
for p in Primes:
    NC = defaultdict(lambda: -1)
    N = C.keys()
    for i in N:
        NC[i] = max(NC[i], C[i])
        if i + p <= n:
            NC[i + p] = max(NC[i + p], C[i] + 1)
    C = NC
print(C[n])
0