結果

問題 No.247 線形計画問題もどき
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-09-14 22:50:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,593 ms / 2,000 ms
コード長 357 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 16,044 KB
最終ジャッジ日時 2023-09-21 17:33:10
合計ジャッジ時間 7,560 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
15,564 KB
testcase_01 AC 83 ms
15,144 KB
testcase_02 AC 1,593 ms
15,828 KB
testcase_03 AC 81 ms
15,328 KB
testcase_04 AC 82 ms
15,328 KB
testcase_05 AC 81 ms
15,048 KB
testcase_06 AC 81 ms
15,172 KB
testcase_07 AC 88 ms
16,044 KB
testcase_08 AC 107 ms
15,872 KB
testcase_09 AC 82 ms
15,028 KB
testcase_10 AC 88 ms
15,948 KB
testcase_11 AC 80 ms
15,164 KB
testcase_12 AC 81 ms
15,224 KB
testcase_13 AC 80 ms
15,032 KB
testcase_14 AC 81 ms
15,152 KB
testcase_15 AC 80 ms
15,156 KB
testcase_16 AC 81 ms
15,240 KB
testcase_17 AC 203 ms
15,556 KB
testcase_18 AC 98 ms
15,264 KB
testcase_19 AC 290 ms
15,808 KB
testcase_20 AC 841 ms
15,792 KB
testcase_21 AC 83 ms
15,272 KB
testcase_22 AC 102 ms
15,292 KB
testcase_23 AC 82 ms
15,220 KB
testcase_24 AC 781 ms
15,928 KB
testcase_25 AC 577 ms
15,680 KB
testcase_26 AC 86 ms
15,644 KB
testcase_27 AC 85 ms
15,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
INF = 10 ** 7
c,n = 2.times.map { gets.to_i }
a = gets.split.map(&:to_i).sort
dp = Array.new(c+1,INF)
dp[0] = 0
(0..c).each do |i|
    if dp[i] < INF
        n.times do |j|
            if i + a[j] <= c
                dp[i + a[j]] = [dp[i + a[j]], dp[i] + 1].min
            end
        end
    end
end
dp[c] = -1 if dp[c] > c
puts dp[c]
0