結果

問題 No.247 線形計画問題もどき
ユーザー finefine
提出日時 2016-04-04 23:08:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,598 ms / 2,000 ms
コード長 406 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,300 KB
実行使用メモリ 94,448 KB
最終ジャッジ日時 2023-09-21 17:37:08
合計ジャッジ時間 12,704 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 602 ms
49,728 KB
testcase_01 AC 78 ms
15,052 KB
testcase_02 AC 1,598 ms
94,448 KB
testcase_03 AC 76 ms
15,140 KB
testcase_04 AC 75 ms
15,292 KB
testcase_05 AC 75 ms
15,244 KB
testcase_06 AC 78 ms
15,176 KB
testcase_07 AC 127 ms
19,276 KB
testcase_08 AC 91 ms
16,672 KB
testcase_09 AC 75 ms
15,152 KB
testcase_10 AC 85 ms
16,848 KB
testcase_11 AC 76 ms
15,328 KB
testcase_12 AC 75 ms
15,132 KB
testcase_13 AC 74 ms
15,244 KB
testcase_14 AC 75 ms
15,188 KB
testcase_15 AC 75 ms
15,280 KB
testcase_16 AC 76 ms
15,256 KB
testcase_17 AC 464 ms
42,776 KB
testcase_18 AC 90 ms
15,900 KB
testcase_19 AC 942 ms
72,096 KB
testcase_20 AC 1,136 ms
81,240 KB
testcase_21 AC 624 ms
56,740 KB
testcase_22 AC 680 ms
62,352 KB
testcase_23 AC 577 ms
53,400 KB
testcase_24 AC 1,158 ms
81,348 KB
testcase_25 AC 906 ms
67,864 KB
testcase_26 AC 237 ms
26,216 KB
testcase_27 AC 369 ms
35,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:20: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

INF = 1000000
c = gets.to_i
n = gets.to_i
a = gets.split.map(&:to_i)
dp = Array.new(n + 1)
(n + 1).times{|i|
    dp[i] = Array.new(c + 1,INF)
    dp[i][0] = 0
    }

1.upto(n){|i|
    1.upto(a[i - 1] - 1){|j|
        dp[i][j] = dp[i - 1][j]
        }
    a[i - 1].upto(c){|j|
        dp[i][j] = [dp[i - 1][j], dp[i][j - a[i - 1]] + 1].min
        }
    }
if dp[n][c] == INF
    p -1
else
    p dp[n][c]
end
0