結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2019-05-29 14:05:03 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 1,901 ms / 5,000 ms |
コード長 | 590 bytes |
コンパイル時間 | 69 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,672 KB |
最終ジャッジ日時 | 2024-07-20 16:40:10 |
合計ジャッジ時間 | 16,734 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
Syntax OK
ソースコード
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