結果

問題 No.458 異なる素数の和
ユーザー satama123satama123
提出日時 2023-11-11 23:34:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,615 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 420,112 KB
最終ジャッジ日時 2023-11-11 23:35:01
合計ジャッジ時間 11,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
66,024 KB
testcase_01 AC 512 ms
176,304 KB
testcase_02 AC 659 ms
201,520 KB
testcase_03 AC 154 ms
88,752 KB
testcase_04 AC 196 ms
104,496 KB
testcase_05 AC 1,357 ms
360,572 KB
testcase_06 AC 630 ms
200,112 KB
testcase_07 AC 61 ms
68,116 KB
testcase_08 AC 1,365 ms
363,040 KB
testcase_09 AC 95 ms
82,168 KB
testcase_10 AC 33 ms
53,460 KB
testcase_11 AC 1,615 ms
420,112 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 34 ms
53,460 KB
testcase_14 AC 34 ms
53,460 KB
testcase_15 AC 34 ms
53,460 KB
testcase_16 AC 125 ms
88,100 KB
testcase_17 AC 39 ms
59,632 KB
testcase_18 AC 39 ms
59,760 KB
testcase_19 AC 33 ms
53,460 KB
testcase_20 AC 43 ms
61,864 KB
testcase_21 AC 34 ms
53,460 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 45 ms
61,864 KB
testcase_24 AC 42 ms
61,864 KB
testcase_25 AC 34 ms
53,460 KB
testcase_26 AC 38 ms
59,632 KB
testcase_27 AC 600 ms
193,712 KB
testcase_28 AC 1,581 ms
412,252 KB
testcase_29 AC 70 ms
72,500 KB
testcase_30 AC 386 ms
148,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

prime = [True] * (N + 1)
P = []
for i in range(2, N+1):
    if prime[i]:
        P.append(i)
        for j in range(i+i, N+1, i):
            prime[j] = False

n = len(P)

dp = [[-1 for _ in range(N + 1)] for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    p = P[i]

    for j in range(N + 1):
        if dp[i][j] == -1 : continue

        if dp[i + 1][j] == -1 : dp[i + 1][j] = dp[i][j]
        else : dp[i + 1][j] = max(dp[i+1][j], dp[i][j])

        if j + p > N : continue
        if dp[i + 1][j + p] == -1 : dp[i + 1][j + p] = dp[i][j] + 1
        else : dp[i + 1][j + p] = max(dp[i+1][j + p], dp[i][j] + 1)


print(dp[n][N])
0