結果

問題 No.3063 幅優先探索
ユーザー onakasuitacityonakasuitacity
提出日時 2020-04-01 22:35:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 696,020 KB
最終ジャッジ日時 2023-09-09 19:15:08
合計ジャッジ時間 4,748 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

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