結果

問題 No.3063 幅優先探索
ユーザー 67oYG9nh2YMmIci67oYG9nh2YMmIci
提出日時 2021-06-12 15:36:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 819 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 103,552 KB
最終ジャッジ日時 2024-05-09 19:11:35
合計ジャッジ時間 5,765 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
16,128 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 33 ms
10,624 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

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