結果

問題 No.458 異なる素数の和
ユーザー masashi0217masashi0217
提出日時 2021-03-31 02:14:46
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 364 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 11,352 KB
実行使用メモリ 15,536 KB
最終ジャッジ日時 2023-08-20 21:57:02
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 94 ms
15,148 KB
testcase_11 WA -
testcase_12 AC 95 ms
15,260 KB
testcase_13 AC 92 ms
15,144 KB
testcase_14 AC 93 ms
15,064 KB
testcase_15 AC 95 ms
15,336 KB
testcase_16 WA -
testcase_17 AC 94 ms
15,216 KB
testcase_18 AC 94 ms
15,276 KB
testcase_19 AC 94 ms
15,256 KB
testcase_20 AC 96 ms
15,140 KB
testcase_21 AC 96 ms
15,084 KB
testcase_22 AC 95 ms
15,164 KB
testcase_23 AC 96 ms
15,280 KB
testcase_24 AC 95 ms
15,312 KB
testcase_25 AC 96 ms
15,036 KB
testcase_26 AC 96 ms
15,536 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'
n = gets.chomp.to_i
#素数を固定して回す
max = 200
dp = Array.new(max,0)
a = Prime.each(max).to_a.reverse.map(&:to_i)

a.each do |i|
    dp[i] += 1
end
a.each do |i|
    (max-1-i).downto(i+1) do |j|
        if dp[j] > 0
            dp[i+j] = [dp[j]+1,dp[i+j]].max
        end
    end
end
if dp[n] == 0
    puts "-1"
else
    puts dp[n]
end
0