結果

問題 No.1 道のショートカット
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-29 14:05:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,804 ms / 5,000 ms
コード長 590 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 15,628 KB
最終ジャッジ日時 2023-09-27 22:20:08
合計ジャッジ時間 17,054 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,152 KB
testcase_01 AC 81 ms
15,292 KB
testcase_02 AC 84 ms
15,040 KB
testcase_03 AC 82 ms
15,312 KB
testcase_04 AC 81 ms
15,324 KB
testcase_05 AC 84 ms
15,092 KB
testcase_06 AC 81 ms
15,280 KB
testcase_07 AC 82 ms
15,132 KB
testcase_08 AC 1,407 ms
15,348 KB
testcase_09 AC 766 ms
15,408 KB
testcase_10 AC 436 ms
15,256 KB
testcase_11 AC 509 ms
15,248 KB
testcase_12 AC 1,774 ms
15,528 KB
testcase_13 AC 1,804 ms
15,628 KB
testcase_14 AC 126 ms
15,204 KB
testcase_15 AC 85 ms
15,252 KB
testcase_16 AC 295 ms
15,204 KB
testcase_17 AC 88 ms
15,044 KB
testcase_18 AC 138 ms
15,412 KB
testcase_19 AC 167 ms
15,440 KB
testcase_20 AC 216 ms
15,284 KB
testcase_21 AC 210 ms
15,240 KB
testcase_22 AC 138 ms
15,384 KB
testcase_23 AC 450 ms
15,344 KB
testcase_24 AC 519 ms
15,348 KB
testcase_25 AC 246 ms
15,248 KB
testcase_26 AC 172 ms
15,312 KB
testcase_27 AC 745 ms
15,380 KB
testcase_28 AC 88 ms
15,140 KB
testcase_29 AC 196 ms
15,520 KB
testcase_30 AC 95 ms
15,116 KB
testcase_31 AC 111 ms
15,252 KB
testcase_32 AC 828 ms
15,408 KB
testcase_33 AC 540 ms
15,340 KB
testcase_34 AC 567 ms
15,508 KB
testcase_35 AC 88 ms
15,332 KB
testcase_36 AC 231 ms
15,528 KB
testcase_37 AC 98 ms
15,136 KB
testcase_38 AC 105 ms
15,136 KB
testcase_39 AC 237 ms
15,540 KB
testcase_40 AC 122 ms
15,092 KB
testcase_41 AC 92 ms
15,348 KB
testcase_42 AC 82 ms
15,276 KB
testcase_43 AC 86 ms
15,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i - 1
c = gets.to_i 
v = gets.to_i
s = gets.split.map{|s| s.to_i - 1 }
t = gets.split.map{|s| s.to_i - 1 }
y = gets.split.map(&:to_i) # コスト
m = gets.split.map(&:to_i) # 時間


# dp[現在地点][コスト] = 時間 
dp = Array.new(n + 1){ Array.new(c + 1, Float::INFINITY) }
dp[0][0] = 0

[*0..(n + 1)].product([*0..(c + 1)]) do |current, amount|
  v.times do |i|
    next if current != s[i]
    dp[t[i]][amount + y[i]] = [dp[t[i]][amount + y[i]], dp[current][amount] + m[i]].min if amount + y[i] <= c
  end
end

ans = dp[n].min
puts (ans == Float::INFINITY) ? -1 : ans
0