結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,084 KB
testcase_01 AC 84 ms
16,084 KB
testcase_02 AC 83 ms
16,084 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 80 ms
16,076 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 85 ms
16,084 KB
testcase_09 AC 85 ms
16,084 KB
testcase_10 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]

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