結果

問題 No.527 ナップサック容量問題
ユーザー letrangerjpletrangerjp
提出日時 2017-06-11 01:55:30
言語 Ruby
(3.3.0)
結果
AC  
実行時間 798 ms / 2,000 ms
コード長 209 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 16,548 KB
最終ジャッジ日時 2023-10-24 20:38:03
合計ジャッジ時間 12,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
16,064 KB
testcase_01 AC 83 ms
16,064 KB
testcase_02 AC 86 ms
16,060 KB
testcase_03 AC 84 ms
16,064 KB
testcase_04 AC 83 ms
16,064 KB
testcase_05 AC 199 ms
16,324 KB
testcase_06 AC 661 ms
16,528 KB
testcase_07 AC 432 ms
16,436 KB
testcase_08 AC 162 ms
16,092 KB
testcase_09 AC 83 ms
16,064 KB
testcase_10 AC 629 ms
16,504 KB
testcase_11 AC 306 ms
16,324 KB
testcase_12 AC 213 ms
16,324 KB
testcase_13 AC 696 ms
16,540 KB
testcase_14 AC 171 ms
16,120 KB
testcase_15 AC 282 ms
16,324 KB
testcase_16 AC 84 ms
16,064 KB
testcase_17 AC 204 ms
16,324 KB
testcase_18 AC 244 ms
16,324 KB
testcase_19 AC 84 ms
16,064 KB
testcase_20 AC 164 ms
16,092 KB
testcase_21 AC 777 ms
16,536 KB
testcase_22 AC 445 ms
16,460 KB
testcase_23 AC 668 ms
16,492 KB
testcase_24 AC 112 ms
16,064 KB
testcase_25 AC 370 ms
16,408 KB
testcase_26 AC 317 ms
16,324 KB
testcase_27 AC 343 ms
16,404 KB
testcase_28 AC 295 ms
16,324 KB
testcase_29 AC 798 ms
16,548 KB
testcase_30 AC 84 ms
16,064 KB
testcase_31 AC 84 ms
16,064 KB
testcase_32 AC 85 ms
16,064 KB
testcase_33 AC 84 ms
16,064 KB
testcase_34 AC 84 ms
16,060 KB
testcase_35 AC 312 ms
16,324 KB
testcase_36 AC 85 ms
16,064 KB
testcase_37 AC 213 ms
16,324 KB
testcase_38 AC 274 ms
16,324 KB
testcase_39 AC 243 ms
16,324 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

A=$<.map{|s|s.split.map &:to_i}
N=A.shift[0]
V=A.pop[0]
B,C=A.transpose
d=[]
N.times{|i|C.sum.downto(C[i]){|j|d[j]=[d[j]||0,B[i]+d[j-C[i]]||=0].max}}
p [1,d.index(V)].max
puts V==d[-1]?:inf:[1,d.rindex(V)].max
0