結果

問題 No.1 道のショートカット
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-05-26 09:08:09
言語 Ruby
(3.3.0)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 719 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 15,668 KB
最終ジャッジ日時 2023-09-27 21:44:41
合計ジャッジ時間 5,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,152 KB
testcase_01 AC 75 ms
15,244 KB
testcase_02 AC 75 ms
15,196 KB
testcase_03 AC 77 ms
15,088 KB
testcase_04 AC 72 ms
15,172 KB
testcase_05 AC 76 ms
15,268 KB
testcase_06 AC 72 ms
15,088 KB
testcase_07 AC 78 ms
15,148 KB
testcase_08 AC 81 ms
15,404 KB
testcase_09 AC 76 ms
15,100 KB
testcase_10 AC 75 ms
15,296 KB
testcase_11 AC 76 ms
15,396 KB
testcase_12 AC 78 ms
15,360 KB
testcase_13 AC 82 ms
15,540 KB
testcase_14 AC 75 ms
15,248 KB
testcase_15 AC 72 ms
15,136 KB
testcase_16 AC 76 ms
15,312 KB
testcase_17 AC 72 ms
15,260 KB
testcase_18 AC 75 ms
15,092 KB
testcase_19 AC 78 ms
15,276 KB
testcase_20 AC 75 ms
15,092 KB
testcase_21 AC 74 ms
15,300 KB
testcase_22 AC 74 ms
15,300 KB
testcase_23 AC 108 ms
15,668 KB
testcase_24 AC 79 ms
15,316 KB
testcase_25 AC 74 ms
15,292 KB
testcase_26 AC 77 ms
15,224 KB
testcase_27 AC 84 ms
15,452 KB
testcase_28 AC 73 ms
15,228 KB
testcase_29 AC 78 ms
15,604 KB
testcase_30 AC 80 ms
15,272 KB
testcase_31 AC 78 ms
15,400 KB
testcase_32 AC 82 ms
15,604 KB
testcase_33 AC 78 ms
15,348 KB
testcase_34 AC 78 ms
15,548 KB
testcase_35 AC 80 ms
15,328 KB
testcase_36 AC 79 ms
15,408 KB
testcase_37 AC 77 ms
15,396 KB
testcase_38 AC 73 ms
15,056 KB
testcase_39 AC 73 ms
15,184 KB
testcase_40 AC 74 ms
15,184 KB
testcase_41 AC 78 ms
15,336 KB
testcase_42 AC 75 ms
15,060 KB
testcase_43 AC 77 ms
15,228 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:33: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

# Here your 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 = nil

until q.empty?
    q.sort! { |a, b| a[:m] <=> b[:m] }
    current = q.shift
    pos = current[:pos]
    if pos == n
        g = current
        break
    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.nil?
    puts -1
else
    puts g[:m]
end
0