結果

問題 No.458 異なる素数の和
ユーザー nakamura sosukenakamura sosuke
提出日時 2019-07-18 20:20:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,344 ms / 2,000 ms
コード長 275 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 11,540 KB
実行使用メモリ 15,628 KB
最終ジャッジ日時 2023-08-26 20:34:44
合計ジャッジ時間 44,049 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,297 ms
15,520 KB
testcase_01 AC 1,274 ms
15,520 KB
testcase_02 AC 1,304 ms
15,628 KB
testcase_03 AC 1,279 ms
15,412 KB
testcase_04 AC 1,295 ms
15,424 KB
testcase_05 AC 1,277 ms
15,296 KB
testcase_06 AC 1,284 ms
15,388 KB
testcase_07 AC 1,280 ms
15,352 KB
testcase_08 AC 1,288 ms
15,312 KB
testcase_09 AC 1,322 ms
15,304 KB
testcase_10 AC 1,300 ms
15,600 KB
testcase_11 AC 1,300 ms
15,364 KB
testcase_12 AC 1,295 ms
15,572 KB
testcase_13 AC 1,306 ms
15,412 KB
testcase_14 AC 1,303 ms
15,444 KB
testcase_15 AC 1,298 ms
15,424 KB
testcase_16 AC 1,299 ms
15,308 KB
testcase_17 AC 1,285 ms
15,412 KB
testcase_18 AC 1,289 ms
15,568 KB
testcase_19 AC 1,282 ms
15,504 KB
testcase_20 AC 1,295 ms
15,528 KB
testcase_21 AC 1,274 ms
15,568 KB
testcase_22 AC 1,282 ms
15,508 KB
testcase_23 AC 1,321 ms
15,412 KB
testcase_24 AC 1,300 ms
15,348 KB
testcase_25 AC 1,294 ms
15,524 KB
testcase_26 AC 1,306 ms
15,416 KB
testcase_27 AC 1,302 ms
15,388 KB
testcase_28 AC 1,344 ms
15,580 KB
testcase_29 AC 1,297 ms
15,596 KB
testcase_30 AC 1,292 ms
15,392 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

N = 20000
dp = Array.new(N+1)
dp[0] = 0

Prime.each(N/4) do | p |
  (N-p).downto(0) do | n |
    next unless dp[n]
    unless dp[n+p]
      dp[n+p] = dp[n] + 1
    else
      dp[n+p] = dp[n] + 1 if dp[n] + 1 > dp[n+p]
    end
  end
end

p dp[gets.to_i] || -1
0