結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-26 19:20:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 529 bytes |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 54,656 KB |
| 最終ジャッジ日時 | 2024-10-15 11:27:07 |
| 合計ジャッジ時間 | 5,776 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 3 WA * 4 TLE * 1 -- * 1 |
ソースコード
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])