結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-22 19:34:18 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 972 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-11-27 20:10:03 |
| 合計ジャッジ時間 | 1,852 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
from collections import deque
H, W = map(int, input().split())
sy, sx, gy, gx = map(lambda x: int(x) - 1, input().split())
S = [list(map(int, input())) for _ in range(H)]
visited = [[False] * W for _ in range(H)]
visited[sy][sx] = True
direction = [(-1, 0), (0, 1), (1, 0), (0, -1)]
que = deque([(sy, sx)])
while que:
y, x = que.popleft()
for dy, dx in direction:
ny, nx = y + dy, x + dx
nny, nnx = ny + dy, nx + dx
if not (0 <= ny < H and 0 <= nx < W):
continue
if visited[ny][nx]:
continue
if abs(S[ny][nx] - S[y][x]) <= 1:
visited[ny][nx] = True
que.append((ny, nx))
if not (0 <= nny < H and 0 <= nnx < W):
continue
if visited[nny][nnx]:
continue
if S[nny][nnx] == S[y][x] and S[nny][nnx] > S[ny][nx]:
visited[nny][nnx] = True
que.append((nny, nnx))
print("YES" if visited[gy][gx] else "NO")