結果

問題 No.1 道のショートカット
コンテスト
ユーザー TANIGUCHI Kousuke
提出日時 2015-05-25 18:15:22
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
TLE  
実行時間 -
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 205 ms
コンパイル使用メモリ 9,088 KB
実行使用メモリ 23,844 KB
最終ジャッジ日時 2026-03-29 20:50:34
合計ジャッジ時間 12,840 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 TLE * 2 -- * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-` operator
Syntax OK

ソースコード

diff #
raw source code

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 = []

until q.empty?
    q.sort! { |a, b| a[:m] <=> b[:m] }
    current = q.shift
    pos = current[:pos]
    if pos == n
        g.push(current)
    end
    
    if from_to[pos]
        from_to[pos].each do |to|
            cost = current[:y] + to[:y]
            minute = current[:m] + to[:m]
            if cost <= c
                q.push({ pos: to[:t], y: cost, m: minute} )
            end
        end
    end
end

if g.empty?
    puts -1
else
    puts g.min {|a,b| a[:m] <=> b[:m] }[:m]
end
0