結果

問題 No.458 異なる素数の和
ユーザー lloyz
提出日時 2023-10-16 00:02:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 528 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 176,384 KB
最終ジャッジ日時 2024-09-16 22:08:20
合計ジャッジ時間 9,281 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 4 TLE * 2 -- * 22
権限があれば一括ダウンロードができます

ソースコード

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