結果

問題 No.3063 幅優先探索
ユーザー onakasuitacityonakasuitacity
提出日時 2020-04-01 22:40:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 868 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 101,664 KB
最終ジャッジ日時 2023-09-09 19:23:31
合計ジャッジ時間 2,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,432 KB
testcase_01 AC 91 ms
71,504 KB
testcase_02 AC 91 ms
71,656 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 285 ms
101,664 KB
testcase_08 AC 91 ms
71,796 KB
testcase_09 AC 93 ms
71,620 KB
testcase_10 AC 90 ms
71,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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