結果

問題 No.247 線形計画問題もどき
ユーザー wotsushiwotsushi
提出日時 2017-01-25 21:11:20
言語 Ruby
(3.3.0)
結果
AC  
実行時間 894 ms / 2,000 ms
コード長 292 bytes
コンパイル時間 34 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 16,156 KB
最終ジャッジ日時 2023-09-21 18:21:36
合計ジャッジ時間 5,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
15,780 KB
testcase_01 AC 80 ms
15,144 KB
testcase_02 AC 894 ms
16,016 KB
testcase_03 AC 77 ms
15,048 KB
testcase_04 AC 77 ms
15,236 KB
testcase_05 AC 77 ms
15,156 KB
testcase_06 AC 77 ms
15,324 KB
testcase_07 AC 94 ms
15,948 KB
testcase_08 AC 88 ms
16,156 KB
testcase_09 AC 77 ms
15,248 KB
testcase_10 AC 78 ms
16,092 KB
testcase_11 AC 77 ms
15,080 KB
testcase_12 AC 77 ms
15,392 KB
testcase_13 AC 77 ms
15,152 KB
testcase_14 AC 77 ms
15,164 KB
testcase_15 AC 77 ms
15,140 KB
testcase_16 AC 76 ms
15,240 KB
testcase_17 AC 113 ms
15,416 KB
testcase_18 AC 89 ms
15,188 KB
testcase_19 AC 240 ms
15,756 KB
testcase_20 AC 367 ms
15,712 KB
testcase_21 AC 78 ms
15,220 KB
testcase_22 AC 91 ms
15,448 KB
testcase_23 AC 79 ms
15,112 KB
testcase_24 AC 391 ms
15,920 KB
testcase_25 AC 266 ms
15,836 KB
testcase_26 AC 108 ms
15,840 KB
testcase_27 AC 109 ms
15,392 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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