結果

問題 No.8063 幅優先探索
ユーザー onakasuitacity
提出日時 2020-04-01 22:35:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 701,804 KB
最終ジャッジ日時 2024-06-27 11:50:33
合計ジャッジ時間 4,134 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other WA * 1 RE * 3 MLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
INF = float("inf")

h, w = map(int, input().split())
si, sj = map(lambda x:int(x)-1, input().split())
ti, tj = map(lambda x:int(x)-1, input().split())
G = [input() for _ in range(h)]

D = [(-1, 0), (1, 0), (0, -1), (0, 1)]
Q = deque([(si, sj, 0)])
while 1:
    i, j, d = Q.popleft()
    for di, dj in D:
        ni, nj = i + di, j + dj
        if not (0 <= ni < h and 0 <= nj < w):
            continue
        if G[ni][nj] == '#':
            continue
        if (ni, nj) == (ti, tj):
            print(d)
            exit(0)
        Q.append((di, dj, d + 1))
0