結果

問題 No.1 道のショートカット
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-17 11:09:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 430 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 11,480 KB
実行使用メモリ 16,456 KB
最終ジャッジ日時 2023-09-27 22:13:11
合計ジャッジ時間 6,875 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
15,100 KB
testcase_01 AC 69 ms
15,088 KB
testcase_02 AC 69 ms
15,028 KB
testcase_03 AC 70 ms
15,268 KB
testcase_04 AC 68 ms
15,140 KB
testcase_05 AC 68 ms
15,272 KB
testcase_06 AC 66 ms
15,144 KB
testcase_07 AC 67 ms
15,072 KB
testcase_08 AC 83 ms
15,520 KB
testcase_09 AC 72 ms
15,176 KB
testcase_10 AC 83 ms
15,528 KB
testcase_11 AC 151 ms
15,660 KB
testcase_12 AC 187 ms
16,456 KB
testcase_13 AC 170 ms
16,308 KB
testcase_14 AC 68 ms
15,136 KB
testcase_15 AC 68 ms
15,136 KB
testcase_16 AC 72 ms
15,064 KB
testcase_17 AC 70 ms
15,172 KB
testcase_18 AC 69 ms
15,272 KB
testcase_19 AC 71 ms
15,088 KB
testcase_20 AC 82 ms
15,536 KB
testcase_21 AC 72 ms
15,248 KB
testcase_22 AC 72 ms
15,152 KB
testcase_23 AC 400 ms
15,772 KB
testcase_24 AC 430 ms
15,860 KB
testcase_25 AC 106 ms
15,464 KB
testcase_26 AC 91 ms
15,448 KB
testcase_27 AC 285 ms
16,220 KB
testcase_28 AC 71 ms
15,156 KB
testcase_29 AC 97 ms
15,568 KB
testcase_30 AC 74 ms
15,168 KB
testcase_31 AC 94 ms
15,432 KB
testcase_32 AC 99 ms
15,588 KB
testcase_33 AC 84 ms
15,524 KB
testcase_34 AC 213 ms
15,796 KB
testcase_35 AC 72 ms
15,288 KB
testcase_36 AC 76 ms
15,220 KB
testcase_37 AC 72 ms
15,264 KB
testcase_38 AC 67 ms
15,240 KB
testcase_39 AC 70 ms
15,300 KB
testcase_40 AC 71 ms
15,236 KB
testcase_41 AC 69 ms
15,284 KB
testcase_42 AC 67 ms
15,132 KB
testcase_43 AC 69 ms
15,324 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

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
0