結果

問題 No.527 ナップサック容量問題
ユーザー 0w10w1
提出日時 2017-08-09 10:48:02
言語 Ruby
(3.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 525 bytes
コンパイル時間 60 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-20 08:27:57
合計ジャッジ時間 42,890 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
12,800 KB
testcase_01 AC 174 ms
13,056 KB
testcase_02 AC 128 ms
12,928 KB
testcase_03 AC 177 ms
12,800 KB
testcase_04 AC 108 ms
12,672 KB
testcase_05 AC 962 ms
12,800 KB
testcase_06 AC 1,974 ms
12,800 KB
testcase_07 AC 1,570 ms
12,800 KB
testcase_08 AC 847 ms
12,800 KB
testcase_09 AC 110 ms
12,800 KB
testcase_10 TLE -
testcase_11 AC 1,429 ms
12,672 KB
testcase_12 AC 1,032 ms
12,800 KB
testcase_13 TLE -
testcase_14 AC 761 ms
12,672 KB
testcase_15 AC 1,192 ms
12,672 KB
testcase_16 AC 178 ms
12,800 KB
testcase_17 AC 1,032 ms
12,800 KB
testcase_18 AC 1,128 ms
12,928 KB
testcase_19 AC 194 ms
12,800 KB
testcase_20 AC 813 ms
12,928 KB
testcase_21 TLE -
testcase_22 AC 1,529 ms
12,800 KB
testcase_23 TLE -
testcase_24 AC 516 ms
12,928 KB
testcase_25 AC 1,491 ms
12,800 KB
testcase_26 AC 1,328 ms
12,928 KB
testcase_27 AC 1,354 ms
12,800 KB
testcase_28 AC 1,180 ms
12,800 KB
testcase_29 TLE -
testcase_30 AC 279 ms
12,800 KB
testcase_31 AC 1,005 ms
12,928 KB
testcase_32 AC 1,238 ms
12,672 KB
testcase_33 AC 1,039 ms
12,800 KB
testcase_34 AC 1,273 ms
12,800 KB
testcase_35 AC 1,271 ms
12,800 KB
testcase_36 AC 152 ms
12,928 KB
testcase_37 AC 960 ms
12,672 KB
testcase_38 AC 1,186 ms
12,672 KB
testcase_39 AC 1,101 ms
12,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
V, W = [], []
N.times do |i|
  v, w = gets.split.map &:to_i
  V << v
  W << w
end
VALUE = gets.to_i

dp = [-1.to_i] * (1e5.to_i + 1)
dp[0] = 0
N.times do |i|
  1e5.to_i.downto(0) do |j|
    next if dp[i][j] == -1
    dp[j + W[i]] = [dp[j + W[i]], dp[j] + V[i]].max if j + W[i] <= 1e5.to_i
  end
end
_ = 0
(1e5 + 1).to_i.times do |i|
  _ = [_, dp[i]].max
  dp[i] = [dp[i], _].max
end

puts [dp.find_index(VALUE), 1].max
puts VALUE == V.inject(:+) ? "inf" : dp[0..1e5.to_i].take_while { |x| x <= VALUE }.size - 1
0