結果

問題 No.8063 幅優先探索
コンテスト
ユーザー onakasuitacity
提出日時 2020-04-01 22:35:37
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 590 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 134 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 1,106,288 KB
最終ジャッジ日時 2026-03-15 06:44:11
合計ジャッジ時間 16,176 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 2
other WA * 1 RE * 3 TLE * 3 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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