結果

問題 No.3063 幅優先探索
ユーザー DrDrpilotDrDrpilot
提出日時 2022-03-26 19:20:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 54,528 KB
最終ジャッジ日時 2024-04-23 11:30:41
合計ジャッジ時間 6,083 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
16,384 KB
testcase_01 AC 33 ms
10,752 KB
testcase_02 AC 32 ms
10,752 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
r,c=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())
sy-=1;sx-=1;gy-=1;gx-=1
g=[input() for _ in range(r)]
d=[[-1]*c for _ in range(r)]
q=deque()
d[sy][sx]=0
q.append((sy,sx))
while q:
    y,x=q.popleft()
    dy=[0,1,0,-1]
    dx=[1,0,-1,0]
    for i in range(4):
        ny=y+dy[i];nx=x+dx[i]
        if 0<=ny<r and 0<=nx<c:
            if d[ny][nx]==-1 and g[ny][nx]=='.':
                d[ny][nx]=d[y][x]+1
                q.append((ny,nx))
print(d[gy][gx])
0