結果

問題 No.1638 Robot Maze
ユーザー 小野寺健
提出日時 2021-11-29 09:15:08
言語 Ruby
(3.4.1)
結果
AC  
実行時間 903 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-07-02 06:52:08
合計ジャッジ時間 14,386 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
プレゼンテーションモードにする

H, W = gets.split(" ").map{|s| s.to_i}
U, D, R, L, K, P = gets.split(" ").map{|s| s.to_i}
xs, ys, xt, yt = gets.split(" ").map{|s| s.to_i - 1}
c = []
H.times {
c << gets.strip
}
dir = [[-1, 0, U], [1, 0, D], [0, 1, R], [0, -1, L]]
d = Array.new(H) {Array.new(W, Float::INFINITY)}
d[xs][ys] = 0
que = [[xs, ys, 0]]
while que.length > 0 do
x, y, cost = que.shift
dir.each {|dx, dy, dc|
nx, ny = x + dx, y + dy
next if nx < 0 or nx >= H or ny < 0 or ny >= W or c[nx][ny] == "#"
nc = cost + dc + (c[nx][ny] == "@" ? P : 0)
if d[nx][ny] > nc then
d[nx][ny] = nc
que << [nx, ny, nc]
end
}
end
puts d[xt][yt] <= K ? "Yes" : "No"
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0