結果
| 問題 | No.8063 幅優先探索 |
| コンテスト | |
| ユーザー |
onakasuitacity
|
| 提出日時 | 2020-04-01 22:40:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 868 bytes |
| 記録 | |
| コンパイル時間 | 166 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 101,504 KB |
| 最終ジャッジ日時 | 2024-06-27 11:58:49 |
| 合計ジャッジ時間 | 1,523 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 4 |
ソースコード
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()
onakasuitacity