結果

問題 No.458 異なる素数の和
ユーザー cshimegicshimegi
提出日時 2020-12-05 14:27:34
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 418 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 525,788 KB
最終ジャッジ日時 2023-10-13 21:51:59
合計ジャッジ時間 9,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,084 KB
testcase_01 AC 361 ms
178,852 KB
testcase_02 AC 441 ms
215,580 KB
testcase_03 AC 143 ms
93,124 KB
testcase_04 AC 167 ms
105,380 KB
testcase_05 AC 914 ms
462,380 KB
testcase_06 AC 503 ms
215,920 KB
testcase_07 AC 83 ms
75,672 KB
testcase_08 AC 880 ms
468,280 KB
testcase_09 AC 104 ms
80,916 KB
testcase_10 AC 71 ms
71,300 KB
testcase_11 MLE -
testcase_12 AC 71 ms
71,284 KB
testcase_13 AC 70 ms
71,488 KB
testcase_14 AC 69 ms
71,236 KB
testcase_15 AC 69 ms
71,500 KB
testcase_16 AC 116 ms
81,632 KB
testcase_17 AC 74 ms
75,784 KB
testcase_18 AC 74 ms
75,860 KB
testcase_19 AC 70 ms
70,940 KB
testcase_20 AC 77 ms
75,944 KB
testcase_21 AC 68 ms
71,152 KB
testcase_22 AC 69 ms
71,408 KB
testcase_23 AC 75 ms
75,876 KB
testcase_24 AC 76 ms
75,980 KB
testcase_25 AC 71 ms
71,312 KB
testcase_26 AC 73 ms
75,712 KB
testcase_27 AC 411 ms
203,440 KB
testcase_28 MLE -
testcase_29 AC 90 ms
76,000 KB
testcase_30 AC 286 ms
154,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = [1]*(n+1)
p = 2
while p*p <= n:
    if s[p]:
        for i in range(p*2, n+1, p):
            s[i] = 0
    p += 1

nn = range(n+1)
dp = [[0]+[-1]*n]
add_dp = dp.append
i = 0

for k in range(2, n+1):
    if s[k]:
        add_dp([0]+[-1]*n)
        for w in nn:
            dp[i][w] = max(1+dp[i-1][w-k], dp[i-1][w]) if k <= w and dp[i-1][w-k] != -1 else dp[i-1][w]
        i += 1

print(dp[i-1][n])
0