結果

問題 No.527 ナップサック容量問題
ユーザー 0w10w1
提出日時 2017-08-09 11:03:55
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,588 ms / 2,000 ms
コード長 387 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-20 08:30:27
合計ジャッジ時間 31,738 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
13,696 KB
testcase_01 AC 164 ms
13,568 KB
testcase_02 AC 136 ms
13,696 KB
testcase_03 AC 168 ms
13,568 KB
testcase_04 AC 124 ms
13,440 KB
testcase_05 AC 701 ms
13,440 KB
testcase_06 AC 1,374 ms
13,696 KB
testcase_07 AC 1,116 ms
13,440 KB
testcase_08 AC 611 ms
13,440 KB
testcase_09 AC 118 ms
13,440 KB
testcase_10 AC 1,374 ms
13,312 KB
testcase_11 AC 1,000 ms
13,440 KB
testcase_12 AC 745 ms
13,568 KB
testcase_13 AC 1,410 ms
13,568 KB
testcase_14 AC 572 ms
13,312 KB
testcase_15 AC 851 ms
13,568 KB
testcase_16 AC 167 ms
13,312 KB
testcase_17 AC 722 ms
13,440 KB
testcase_18 AC 841 ms
13,696 KB
testcase_19 AC 183 ms
13,440 KB
testcase_20 AC 604 ms
13,696 KB
testcase_21 AC 1,588 ms
13,568 KB
testcase_22 AC 1,090 ms
13,568 KB
testcase_23 AC 1,543 ms
13,568 KB
testcase_24 AC 393 ms
13,440 KB
testcase_25 AC 1,059 ms
13,568 KB
testcase_26 AC 959 ms
13,696 KB
testcase_27 AC 968 ms
13,440 KB
testcase_28 AC 849 ms
13,440 KB
testcase_29 AC 1,578 ms
13,696 KB
testcase_30 AC 241 ms
13,312 KB
testcase_31 AC 733 ms
13,440 KB
testcase_32 AC 883 ms
13,440 KB
testcase_33 AC 766 ms
13,568 KB
testcase_34 AC 918 ms
13,312 KB
testcase_35 AC 906 ms
13,696 KB
testcase_36 AC 149 ms
13,568 KB
testcase_37 AC 703 ms
13,568 KB
testcase_38 AC 868 ms
13,568 KB
testcase_39 AC 808 ms
13,440 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

A = $<.map { |s| s.split.map &:to_i }
N = A.shift[0]
VALUE = A.pop[0]
V, W = A.transpose
dp = [0] + [-1e9.to_i] * 10**5
N.times do |i|
  1e5.to_i.downto(W[i]) do |j|
    dp[j] = [dp[j], V[i] + dp[j - W[i]]].max
  end
end
_ = 0
0.upto(1e5.to_i) do |i|
  _ = [_, dp[i]].max
  dp[i] = [dp[i], _].max
end
puts [1, dp.index(VALUE)].max
puts dp[-1] == VALUE ? :inf : [1, dp.rindex(VALUE)].max
0