結果

問題 No.1 道のショートカット
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-05-25 18:15:22
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 719 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 11,448 KB
実行使用メモリ 20,720 KB
最終ジャッジ日時 2023-09-22 12:15:37
合計ジャッジ時間 7,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,284 KB
testcase_01 AC 79 ms
15,044 KB
testcase_02 AC 81 ms
15,124 KB
testcase_03 AC 80 ms
15,240 KB
testcase_04 AC 81 ms
15,272 KB
testcase_05 AC 80 ms
15,120 KB
testcase_06 AC 79 ms
15,324 KB
testcase_07 AC 78 ms
15,144 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

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