結果

問題 No.1 道のショートカット
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-05-25 18:23:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,649 ms / 5,000 ms
コード長 760 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 16,028 KB
最終ジャッジ日時 2023-09-27 21:44:34
合計ジャッジ時間 7,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
15,312 KB
testcase_01 AC 69 ms
15,252 KB
testcase_02 AC 67 ms
15,072 KB
testcase_03 AC 68 ms
15,108 KB
testcase_04 AC 70 ms
15,312 KB
testcase_05 AC 68 ms
15,120 KB
testcase_06 AC 68 ms
15,132 KB
testcase_07 AC 67 ms
15,068 KB
testcase_08 AC 73 ms
15,432 KB
testcase_09 AC 73 ms
15,096 KB
testcase_10 AC 71 ms
15,404 KB
testcase_11 AC 77 ms
15,528 KB
testcase_12 AC 75 ms
15,372 KB
testcase_13 AC 79 ms
15,752 KB
testcase_14 AC 66 ms
15,028 KB
testcase_15 AC 69 ms
15,060 KB
testcase_16 AC 72 ms
15,372 KB
testcase_17 AC 67 ms
15,148 KB
testcase_18 AC 67 ms
15,076 KB
testcase_19 AC 68 ms
15,148 KB
testcase_20 AC 67 ms
15,308 KB
testcase_21 AC 68 ms
15,276 KB
testcase_22 AC 69 ms
15,112 KB
testcase_23 AC 1,649 ms
16,028 KB
testcase_24 AC 167 ms
15,828 KB
testcase_25 AC 71 ms
15,124 KB
testcase_26 AC 72 ms
15,308 KB
testcase_27 AC 223 ms
15,832 KB
testcase_28 AC 68 ms
15,320 KB
testcase_29 AC 88 ms
15,692 KB
testcase_30 AC 70 ms
15,320 KB
testcase_31 AC 89 ms
15,696 KB
testcase_32 AC 90 ms
15,460 KB
testcase_33 AC 72 ms
15,268 KB
testcase_34 AC 95 ms
15,636 KB
testcase_35 AC 329 ms
15,556 KB
testcase_36 AC 75 ms
15,484 KB
testcase_37 AC 83 ms
15,612 KB
testcase_38 AC 68 ms
15,036 KB
testcase_39 AC 69 ms
15,220 KB
testcase_40 AC 69 ms
15,032 KB
testcase_41 AC 68 ms
15,112 KB
testcase_42 AC 68 ms
15,076 KB
testcase_43 AC 67 ms
15,276 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:32: 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 = 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
0