結果

問題 No.8063 幅優先探索
ユーザー 67oYG9nh2YMmIci
提出日時 2021-06-12 15:41:21
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 823 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 122,752 KB
最終ジャッジ日時 2024-12-16 11:03:06
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys

R, C = map(int, input().split())

sx, sy = map(int, input().split())
gx, gy = map(int, input().split())
sy = sy-1
sx = sx-1
gy = gy-1
gx = gx-1
c = []

for i in range(R):
    r = list(input())
    c.append(r)

depth = 0
q = deque()
q.append([sx, sy, depth])
twd = [[1, 0], [0, 1], [-1, 0], [0, -1]]
visited = [([0] * C) for i in range(R)]

while q:
    x, y, d = q.popleft()
    for i in range(4):
        dx, dy = x + twd[i][0], y + twd[i][1]
        if (dx < 0) or (dx >= C):
            continue
        if (dy < 0) or (dy >= R):
            continue
        # if c[dx][dy] == "#":
        #     continue
        if visited[dx][dy] == 1:
            continue
        q.append([dx, dy, d+1])
    visited[x][y] = 1
    if visited[gx][gy] == 1:
        print(d)
        sys.exit()
0