結果

問題 No.385 カップ麺生活
ユーザー yozayoza
提出日時 2015-12-24 21:59:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-15 07:26:02
合計ジャッジ時間 6,899 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
12,416 KB
testcase_01 AC 152 ms
12,288 KB
testcase_02 AC 153 ms
12,160 KB
testcase_03 AC 151 ms
12,032 KB
testcase_04 AC 151 ms
12,288 KB
testcase_05 AC 150 ms
12,288 KB
testcase_06 AC 156 ms
12,288 KB
testcase_07 AC 153 ms
12,288 KB
testcase_08 AC 150 ms
12,160 KB
testcase_09 AC 152 ms
12,160 KB
testcase_10 AC 182 ms
12,160 KB
testcase_11 AC 148 ms
12,160 KB
testcase_12 AC 153 ms
12,032 KB
testcase_13 AC 157 ms
12,288 KB
testcase_14 AC 156 ms
12,288 KB
testcase_15 AC 155 ms
12,160 KB
testcase_16 AC 150 ms
12,416 KB
testcase_17 AC 163 ms
12,288 KB
testcase_18 AC 153 ms
12,160 KB
testcase_19 AC 152 ms
12,160 KB
testcase_20 AC 157 ms
12,160 KB
testcase_21 AC 157 ms
12,288 KB
testcase_22 AC 156 ms
12,288 KB
testcase_23 AC 157 ms
12,288 KB
testcase_24 AC 156 ms
12,160 KB
testcase_25 AC 152 ms
12,032 KB
testcase_26 AC 151 ms
12,160 KB
testcase_27 AC 153 ms
12,160 KB
testcase_28 AC 160 ms
12,160 KB
testcase_29 AC 155 ms
12,288 KB
testcase_30 AC 160 ms
12,160 KB
testcase_31 AC 152 ms
12,288 KB
testcase_32 AC 162 ms
12,032 KB
testcase_33 AC 162 ms
12,032 KB
testcase_34 AC 154 ms
12,160 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