結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
67oYG9nh2YMmIci
|
| 提出日時 | 2021-06-12 15:36:49 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 819 bytes |
| コンパイル時間 | 592 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 111,872 KB |
| 最終ジャッジ日時 | 2024-12-16 10:57:20 |
| 合計ジャッジ時間 | 5,623 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 4 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) 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()
67oYG9nh2YMmIci