結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-03 13:49:16 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 735 bytes |
| コンパイル時間 | 105 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 13,056 KB |
| 最終ジャッジ日時 | 2024-07-08 05:12:00 |
| 合計ジャッジ時間 | 4,724 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 4 |
| other | RE * 40 |
コンパイルメッセージ
Syntax OK
ソースコード
def main
n = gets.to_i
c = gets.to_i
v = gets.to_i
s = gets.split.map(&:to_i)
t = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
m = gets.split.map(&:to_i)
ways = []
v.times do |i|
ways << { s: s[i], t: t[i], y: y[i], m: m[i] }
end
ways_from = ways.group_by { |way| way[:s] }
queue = [{ pos: 1, cost: c, time: 0 }]
result = nil
until queue.empty?
queue.sort_by! { |q| q[:time] }
cur = queue.shift
if n == cur[:pos]
result = cur
break
end
ways_from[cur[:pos]].each do |nxt|
next if cur[:cost] < nxt[:y]
queue << { pos: nxt[:t], cost: cur[:cost] - nxt[:y], time: cur[:time] + nxt[:m] }
end
end
result.present? ? result[:time] : -1
end
puts main