結果

問題 No.1 道のショートカット
ユーザー suppy193
提出日時 2015-06-17 14:51:14
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-07-08 04:07:38
合計ジャッジ時間 5,980 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 7 WA * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - v
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
c = gets.chomp.to_i
v = gets.chomp.to_i
s = gets.chomp.split(' ')
t = gets.chomp.split(' ')
y = gets.chomp.split(' ')
m = gets.chomp.split(' ')
matrix = {}
sum_m = {}
sum_m[1] = [0, 0]
(1..n).each do |i|
	matrix[[s[i - 1].to_i, t[i - 1].to_i]] = [y[i - 1].to_i, m[i - 1].to_i]	
end
#p matrix.sort
(1...n).each do |i|
	next if !sum_m.key?(i)
	(i+1..n).each do |j|
		next if !matrix.key?([i, j])
		#print "#{i},#{j}\n"
		if !sum_m.key?(j)
			sum_m[j] = [c, 1000]	
		end
		if sum_m[j][1] > sum_m[i][1] + matrix[[i, j]][1] && sum_m[i][0] + matrix[[i, j]][0] <= c
			sum_m[j] = [sum_m[i][0] + matrix[[i, j]][0], sum_m[i][1] + matrix[[i, j]][1]]
		end
		#p sum_m
	end
end
if !sum_m.key?(n)
	puts '-1'
else
	puts sum_m[n][1]
end
0