結果

問題 No.385 カップ麺生活
ユーザー tomeruntomerun
提出日時 2016-07-18 02:08:43
言語 Ruby
(3.2.2)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 313 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 15,652 KB
最終ジャッジ日時 2023-07-27 20:53:03
合計ジャッジ時間 5,930 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
15,404 KB
testcase_01 AC 91 ms
15,148 KB
testcase_02 AC 90 ms
15,300 KB
testcase_03 AC 91 ms
15,216 KB
testcase_04 AC 93 ms
15,344 KB
testcase_05 AC 89 ms
15,296 KB
testcase_06 AC 97 ms
15,292 KB
testcase_07 AC 95 ms
15,148 KB
testcase_08 AC 93 ms
15,280 KB
testcase_09 AC 89 ms
15,352 KB
testcase_10 AC 128 ms
15,556 KB
testcase_11 AC 88 ms
15,224 KB
testcase_12 AC 99 ms
15,144 KB
testcase_13 AC 102 ms
15,348 KB
testcase_14 AC 105 ms
15,584 KB
testcase_15 AC 103 ms
15,436 KB
testcase_16 AC 91 ms
15,288 KB
testcase_17 AC 111 ms
15,440 KB
testcase_18 AC 96 ms
15,216 KB
testcase_19 AC 93 ms
15,192 KB
testcase_20 AC 102 ms
15,316 KB
testcase_21 AC 109 ms
15,572 KB
testcase_22 AC 103 ms
15,452 KB
testcase_23 AC 109 ms
15,428 KB
testcase_24 AC 104 ms
15,428 KB
testcase_25 AC 89 ms
15,408 KB
testcase_26 AC 97 ms
15,436 KB
testcase_27 AC 99 ms
15,476 KB
testcase_28 AC 100 ms
15,376 KB
testcase_29 AC 94 ms
15,220 KB
testcase_30 AC 104 ms
15,428 KB
testcase_31 AC 90 ms
15,408 KB
testcase_32 AC 94 ms
15,200 KB
testcase_33 AC 108 ms
15,360 KB
testcase_34 AC 98 ms
15,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

require 'prime'
m = gets.to_i
n = gets.to_i
c = gets.split.map(&:to_i)

dp = Array.new(m+1, -1)
dp[m] = 0
m.downto(1) { |i|
	next if m[i] < 0
	c.each { |j|
		dp[i-j] = [dp[i-j], dp[i]+1].max if dp[i] >= 0 && j <= i
	}
}

puts dp.max + dp.each_with_index.inject(0) {|p,c| p + (c[1].prime? && c[0] > 0 ? c[0] : 0)}
0