結果

問題 No.247 線形計画問題もどき
ユーザー wotsushiwotsushi
提出日時 2017-01-25 21:05:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,217 ms / 2,000 ms
コード長 283 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 11,392 KB
実行使用メモリ 16,040 KB
最終ジャッジ日時 2023-09-21 18:21:45
合計ジャッジ時間 8,116 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 279 ms
15,612 KB
testcase_01 AC 79 ms
15,020 KB
testcase_02 AC 1,217 ms
15,908 KB
testcase_03 AC 78 ms
15,092 KB
testcase_04 AC 78 ms
15,256 KB
testcase_05 AC 78 ms
15,248 KB
testcase_06 AC 78 ms
15,084 KB
testcase_07 AC 132 ms
16,040 KB
testcase_08 AC 96 ms
15,796 KB
testcase_09 AC 78 ms
15,288 KB
testcase_10 AC 79 ms
15,800 KB
testcase_11 AC 78 ms
15,296 KB
testcase_12 AC 78 ms
15,152 KB
testcase_13 AC 80 ms
15,052 KB
testcase_14 AC 79 ms
15,040 KB
testcase_15 AC 79 ms
15,248 KB
testcase_16 AC 78 ms
15,196 KB
testcase_17 AC 175 ms
15,484 KB
testcase_18 AC 91 ms
15,036 KB
testcase_19 AC 549 ms
15,664 KB
testcase_20 AC 705 ms
15,888 KB
testcase_21 AC 81 ms
15,372 KB
testcase_22 AC 122 ms
15,392 KB
testcase_23 AC 88 ms
15,348 KB
testcase_24 AC 884 ms
15,972 KB
testcase_25 AC 530 ms
15,896 KB
testcase_26 AC 174 ms
15,784 KB
testcase_27 AC 173 ms
15,520 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

C = gets.to_i
N = gets.to_i
a = gets.split.map(&:to_i)
dp = Array.new(C + 1, Float::INFINITY)
dp[0] = 0
a.each do |x|
  (0..C-x).each do |y|
    dp[y + x] = [dp[y + x], dp[y] + 1].min
  end
end
ans = if dp [C] < Float::INFINITY
        dp[C]
      else
        -1
      end
puts ans
0