結果

問題 No.458 異なる素数の和
ユーザー wotsushiwotsushi
提出日時 2016-12-10 20:43:08
言語 Ruby
(3.3.0)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 204 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 11,284 KB
実行使用メモリ 15,676 KB
最終ジャッジ日時 2023-09-18 15:04:44
合計ジャッジ時間 7,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
15,184 KB
testcase_01 AC 267 ms
15,656 KB
testcase_02 AC 293 ms
15,348 KB
testcase_03 AC 159 ms
15,564 KB
testcase_04 AC 168 ms
15,292 KB
testcase_05 AC 422 ms
15,496 KB
testcase_06 AC 285 ms
15,420 KB
testcase_07 AC 99 ms
15,568 KB
testcase_08 AC 424 ms
15,632 KB
testcase_09 AC 123 ms
15,288 KB
testcase_10 AC 92 ms
15,208 KB
testcase_11 AC 468 ms
15,676 KB
testcase_12 AC 92 ms
15,136 KB
testcase_13 AC 93 ms
15,192 KB
testcase_14 AC 94 ms
15,364 KB
testcase_15 AC 92 ms
15,328 KB
testcase_16 AC 140 ms
15,372 KB
testcase_17 AC 93 ms
15,328 KB
testcase_18 AC 94 ms
15,344 KB
testcase_19 AC 95 ms
15,200 KB
testcase_20 AC 94 ms
15,348 KB
testcase_21 AC 94 ms
15,400 KB
testcase_22 AC 94 ms
15,436 KB
testcase_23 AC 92 ms
15,200 KB
testcase_24 AC 92 ms
15,212 KB
testcase_25 AC 95 ms
15,216 KB
testcase_26 AC 96 ms
15,196 KB
testcase_27 AC 280 ms
15,420 KB
testcase_28 AC 458 ms
15,400 KB
testcase_29 AC 113 ms
15,588 KB
testcase_30 AC 229 ms
15,408 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"

N = gets.to_i
dp = Array.new(N + 1, -Float::INFINITY)
dp[0] = 0
Prime.each(499) {|p|
  (N - p).downto(0).each {|i| dp[i + p] = [dp[i + p], dp[i] + 1].max}}
ans = [dp[N], -1].max
puts ans
0