結果
問題 |
No.8063 幅優先探索
|
ユーザー |
![]() |
提出日時 | 2021-06-12 15:33:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 822 bytes |
コンパイル時間 | 350 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 121,344 KB |
最終ジャッジ日時 | 2024-12-16 10:53:23 |
合計ジャッジ時間 | 4,452 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 2 WA * 4 RE * 2 TLE * 1 |
ソースコード
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) and (dx >= C): continue if (dy < 0) and (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()