結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2018-03-17 11:09:07 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 506 ms / 5,000 ms |
| コード長 | 683 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 13,440 KB |
| 最終ジャッジ日時 | 2024-07-20 16:35:05 |
| 合計ジャッジ時間 | 6,994 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
Main.rb:45: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:3: warning: assigned but unused variable - v Syntax OK
ソースコード
n=gets.to_i
c=gets.to_i
v=gets.to_i
s=gets.split.map{|e| e.to_i}
t=gets.split.map{|e| e.to_i}
y=gets.split.map{|e| e.to_i}
m=gets.split.map{|e| e.to_i}
g=51.times.map{[]}
s.size.times{|i|
g[s[i]]<<[t[i],y[i],m[i]]
}
hs={}
hs[[1,0]]=0
dp={}
dp[[1,0]]=0
inf=10**9
ans=inf
while dp.empty? == false
dp2={}
dp.each{|e2,v|
if e2[0]==n
ans=[ans,v].min
end
cost=e2[1]
g[e2[0]].each{|e3|
nextCity=e3[0]
addCost=e3[1]
addTime=e3[2]
cost2=cost+addCost
time2=v+addTime
if cost2>c
next
end
e4=[nextCity,cost2]
if hs.key?(e4)==false || hs[e4]>time2
hs[e4]=time2
dp2[e4]=time2
end
}
}
dp=dp2
end
if ans==inf
puts -1
else
puts ans
end
horiesiniti