結果

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

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    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)]
    dist = [[INF]*w for _ in range(h)]
    dist[si][sj] = 0
    Q = deque([(si, sj)])
    while Q:
        i, j = 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 dist[ni][nj] == INF:
                dist[ni][nj] = dist[i][j] + 1
                Q.append((ni, nj))

    print(dist[ti][tj])
resolve()
0