結果

問題 No.3063 幅優先探索
ユーザー simansiman
提出日時 2021-02-24 07:01:24
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 542 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 11,892 KB
実行使用メモリ 84,080 KB
最終ジャッジ日時 2023-10-24 13:35:34
合計ジャッジ時間 5,924 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
16,108 KB
testcase_01 AC 86 ms
16,108 KB
testcase_02 AC 85 ms
16,108 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 AC 88 ms
16,108 KB
testcase_09 AC 85 ms
16,108 KB
testcase_10 AC 84 ms
16,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

R, C = gets.split.map(&:to_i)
SY, SX = gets.split.map(&:to_i)
GY, GX = gets.split.map(&:to_i)
G = R.times.map { gets.chomp.chars }
DY = [-1, 0, 1, 0]
DX = [0, 1, 0, -1]

queue = []
queue << [SY - 1, SX - 1, 0]
visited = Array.new(R) { Array.new(C, false) }

until queue.empty?
  y, x, dist = queue.shift

  if y == GY - 1 && x == GX - 1
    puts dist
    exit
  end

  next if visited[y][x]
  visited[y][x] = true

  4.times do |i|
    ny = y + DY[i]
    nx = x + DX[i]
    next if G[ny][nx] == '#'

    queue << [ny, nx, dist + 1]
  end
end
0