結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2015-05-25 18:23:04 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 2,056 ms / 5,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 68 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-07-20 16:14:26 |
合計ジャッジ時間 | 8,296 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
Main.rb:32: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
n, c, v = 3.times.map { gets.to_i } s, t, y, m = 4.times.map { gets.chomp.split.map(&:to_i) } from_to = v.times.map {|i| { s: s[i], t: t[i], y: y[i], m: m[i] } }.group_by {|v| v[:s] } q = [{pos: 1, y: 0, m: 0}] g = nil until q.empty? q.sort! { |a, b| a[:m] <=> b[:m] } current = q.shift pos = current[:pos] if pos == n g ||= current g = current if g[:m] > current[:m] end if from_to[pos] from_to[pos].each do |to| cost = current[:y] + to[:y] minute = current[:m] + to[:m] if cost <= c && (g.nil? || minute < g[:m]) q.push({ pos: to[:t], y: cost, m: minute} ) end end end end if g.nil? puts -1 else puts g[:m] end