結果

問題 No.458 異なる素数の和
ユーザー netyo715netyo715
提出日時 2022-08-04 00:33:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,490 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 429,044 KB
最終ジャッジ日時 2023-10-11 20:09:38
合計ジャッジ時間 12,112 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,960 KB
testcase_01 AC 454 ms
177,700 KB
testcase_02 AC 552 ms
203,380 KB
testcase_03 AC 163 ms
89,792 KB
testcase_04 AC 182 ms
89,240 KB
testcase_05 AC 1,091 ms
371,704 KB
testcase_06 AC 536 ms
201,744 KB
testcase_07 AC 87 ms
76,096 KB
testcase_08 AC 1,073 ms
374,176 KB
testcase_09 AC 109 ms
76,488 KB
testcase_10 AC 75 ms
71,552 KB
testcase_11 AC 1,490 ms
429,044 KB
testcase_12 AC 449 ms
71,368 KB
testcase_13 AC 73 ms
71,380 KB
testcase_14 AC 76 ms
71,124 KB
testcase_15 AC 74 ms
71,428 KB
testcase_16 AC 137 ms
89,500 KB
testcase_17 AC 78 ms
75,836 KB
testcase_18 AC 78 ms
75,864 KB
testcase_19 AC 73 ms
71,264 KB
testcase_20 AC 79 ms
76,072 KB
testcase_21 AC 75 ms
71,564 KB
testcase_22 AC 74 ms
71,240 KB
testcase_23 AC 79 ms
75,984 KB
testcase_24 AC 82 ms
75,960 KB
testcase_25 AC 75 ms
71,240 KB
testcase_26 AC 78 ms
75,780 KB
testcase_27 AC 499 ms
180,364 KB
testcase_28 AC 1,242 ms
423,344 KB
testcase_29 AC 99 ms
76,312 KB
testcase_30 AC 336 ms
135,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

# dp[i][j] = i こめの素数までを使って j を作るときの素数の個数の最大値

is_sosu = [True]*(N+10)
is_sosu[0] = is_sosu[1] = False
sosu = []
for i in range(N+1):
    if is_sosu[i]:
        sosu.append(i)
        for j in range(i*2, N+1, i):
            is_sosu[j] = False

dp = [[-10**10]*(N+1) for _ in range(len(sosu)+1)]
dp[-1][0] = 0
for i in range(len(sosu)):
    for j in range(N+1):
        dp[i][j] = dp[i-1][j]
        if j >= sosu[i]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-sosu[i]]+1)

ans = dp[len(sosu)-1][N]
if ans < 0:
    print(-1)
else:
    print(ans)
0