結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
neko_the_shadow
|
| 提出日時 | 2019-05-29 13:59:45 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 735 bytes |
| コンパイル時間 | 496 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-07-08 05:10:41 |
| 合計ジャッジ時間 | 7,365 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 16 WA * 24 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.to_i - 1
c = gets.to_i
v = gets.to_i
s = gets.split.map{|s| s.to_i - 1 }
t = gets.split.map{|s| s.to_i - 1 }
y = gets.split.map(&:to_i) # コスト
m = gets.split.map(&:to_i) # 時間
d = Hash.new do |h1, k1|
h1[k1] = Hash.new{|h2, k2| h2[k2] = []}
end
v.times do |i|
d[s[i]][t[i]] = d[t[i]][s[i]] = [y[i], m[i]]
end
# dp[現在地点][コスト] = 時間
dp = Array.new(n + 1){ Array.new(c + 1, Float::INFINITY) }
dp[0][0] = 0
[*0..(n + 1)].product([*0..(c + 1)]) do |current, amount|
d[current].each do |nxt, (cost, hour)|
if amount + cost <= c
dp[nxt][amount + cost] = [dp[nxt][amount + cost], dp[current][amount] + hour].min
end
end
end
ans = dp[n].min
puts (ans == Float::INFINITY) ? -1 : ans
neko_the_shadow