結果

問題 No.458 異なる素数の和
ユーザー cshimegicshimegi
提出日時 2020-12-05 14:43:26
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 904 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 431,156 KB
最終ジャッジ日時 2023-10-13 21:55:37
合計ジャッジ時間 8,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
76,064 KB
testcase_01 AC 348 ms
176,124 KB
testcase_02 AC 416 ms
199,248 KB
testcase_03 AC 134 ms
85,016 KB
testcase_04 AC 146 ms
85,144 KB
testcase_05 AC 821 ms
371,808 KB
testcase_06 AC 404 ms
199,184 KB
testcase_07 AC 84 ms
75,840 KB
testcase_08 AC 772 ms
374,264 KB
testcase_09 AC 98 ms
76,176 KB
testcase_10 AC 69 ms
71,324 KB
testcase_11 AC 904 ms
431,156 KB
testcase_12 AC 70 ms
71,336 KB
testcase_13 AC 71 ms
71,432 KB
testcase_14 AC 71 ms
71,300 KB
testcase_15 AC 71 ms
71,140 KB
testcase_16 AC 117 ms
84,792 KB
testcase_17 AC 75 ms
75,860 KB
testcase_18 AC 77 ms
75,796 KB
testcase_19 AC 71 ms
71,208 KB
testcase_20 AC 76 ms
76,024 KB
testcase_21 AC 70 ms
71,396 KB
testcase_22 AC 70 ms
71,408 KB
testcase_23 AC 76 ms
76,148 KB
testcase_24 AC 76 ms
76,184 KB
testcase_25 AC 71 ms
71,560 KB
testcase_26 AC 74 ms
75,860 KB
testcase_27 AC 374 ms
176,116 KB
testcase_28 AC 887 ms
423,508 KB
testcase_29 AC 90 ms
75,984 KB
testcase_30 AC 259 ms
130,328 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

_ = range(n+1)
__ = [0]+[-1]*n
dp = [__*1]
add = dp.append
i = 0

for k in range(2, n+1):
    if s[k]:
        add(__*1)
        for w in _:
            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