結果

問題 No.385 カップ麺生活
ユーザー yozayoza
提出日時 2015-12-24 21:59:04
言語 Ruby
(3.2.2)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 11,520 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-07-27 20:45:30
合計ジャッジ時間 7,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
15,188 KB
testcase_01 AC 141 ms
15,144 KB
testcase_02 AC 141 ms
15,176 KB
testcase_03 AC 143 ms
15,264 KB
testcase_04 AC 141 ms
15,204 KB
testcase_05 AC 140 ms
15,152 KB
testcase_06 AC 142 ms
15,268 KB
testcase_07 AC 143 ms
15,356 KB
testcase_08 AC 143 ms
15,300 KB
testcase_09 AC 140 ms
15,160 KB
testcase_10 AC 174 ms
15,260 KB
testcase_11 AC 140 ms
15,164 KB
testcase_12 AC 142 ms
15,108 KB
testcase_13 AC 149 ms
15,348 KB
testcase_14 AC 148 ms
15,060 KB
testcase_15 AC 144 ms
15,164 KB
testcase_16 AC 145 ms
15,300 KB
testcase_17 AC 156 ms
15,076 KB
testcase_18 AC 145 ms
15,032 KB
testcase_19 AC 146 ms
15,064 KB
testcase_20 AC 150 ms
15,180 KB
testcase_21 AC 151 ms
15,172 KB
testcase_22 AC 147 ms
15,068 KB
testcase_23 AC 147 ms
15,140 KB
testcase_24 AC 147 ms
15,320 KB
testcase_25 AC 142 ms
15,184 KB
testcase_26 AC 141 ms
15,176 KB
testcase_27 AC 143 ms
15,188 KB
testcase_28 AC 147 ms
15,140 KB
testcase_29 AC 142 ms
15,184 KB
testcase_30 AC 148 ms
15,124 KB
testcase_31 AC 141 ms
15,324 KB
testcase_32 AC 142 ms
15,268 KB
testcase_33 AC 151 ms
15,176 KB
testcase_34 AC 142 ms
15,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

m = gets.to_i
n = gets.to_i
c_list = gets.chomp.split.map(&:to_i)

prime_list = [2]
3.upto(10000) do |i|
  prime_list.push(i) if prime_list.none? {|p| i % p == 0} 
end

dp = Array.new(10001, -1)
dp[m] = 0
c_list.each do |c|
  m.downto(1) do |j|
    k = j - c
    next if dp[j] == -1
    break if k < 0
    dp[k] = [dp[k], dp[j] + 1].max
  end
end

result = 0
prime_list.each do |p|
  result += dp[p] if dp[p] != -1
end

result += dp.max
puts result
0