結果

問題 No.458 異なる素数の和
ユーザー juris_lazyjuris_lazy
提出日時 2022-08-04 13:31:19
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 696 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 634,952 KB
最終ジャッジ日時 2023-10-12 10:57:58
合計ジャッジ時間 13,009 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
76,608 KB
testcase_01 AC 561 ms
256,208 KB
testcase_02 AC 699 ms
324,768 KB
testcase_03 AC 209 ms
118,988 KB
testcase_04 AC 228 ms
121,212 KB
testcase_05 MLE -
testcase_06 AC 693 ms
325,272 KB
testcase_07 AC 97 ms
77,004 KB
testcase_08 MLE -
testcase_09 AC 129 ms
84,152 KB
testcase_10 AC 67 ms
71,436 KB
testcase_11 MLE -
testcase_12 AC 72 ms
71,120 KB
testcase_13 AC 68 ms
71,444 KB
testcase_14 AC 69 ms
71,396 KB
testcase_15 AC 68 ms
71,316 KB
testcase_16 AC 161 ms
97,700 KB
testcase_17 AC 73 ms
76,148 KB
testcase_18 AC 74 ms
76,244 KB
testcase_19 AC 68 ms
71,100 KB
testcase_20 AC 80 ms
76,336 KB
testcase_21 AC 70 ms
71,144 KB
testcase_22 AC 69 ms
71,140 KB
testcase_23 AC 75 ms
76,172 KB
testcase_24 AC 78 ms
76,272 KB
testcase_25 AC 69 ms
71,124 KB
testcase_26 AC 74 ms
76,148 KB
testcase_27 AC 652 ms
302,232 KB
testcase_28 MLE -
testcase_29 AC 117 ms
80,812 KB
testcase_30 AC 439 ms
210,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

N = int(input())
_, table = sieve(N)

dp = [[-float('inf')] * (N + 1) for _ in range(len(table) + 1)]
dp[0][0] = 0
for i in range(len(table)):
  a  = table[i]
  for j in range(N + 1):
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    if j + a <= N:
      dp[i + 1][j + a] = max(dp[i + 1][j + a], dp[i][j] + 1)
if dp[-1][-1] < 0:
  print(-1)
else:
  print(dp[-1][-1])
0