結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2023-08-28 16:56:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,055 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 68,992 KB |
最終ジャッジ日時 | 2024-12-29 22:25:38 |
合計ジャッジ時間 | 2,679 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
from collections import dequeh, w = map(int, input().split())sx, sy, gx, gy = map(int, input().split())sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1b = [list(input()) for _ in range(h)]way = [(-1, 0), (1, 0), (0, -1), (0, 1)]dist = [[float('inf')]*w for _ in range(h)]dist[sx][sy] = 0que = deque([(sx, sy)])while que:x, y = que.popleft()hight = int(b[x][y])for i, j in way:nx = x + iny = y + jif 0 <= nx < h and 0 <= ny < w:nhight = int(b[nx][ny])if -1 <= hight - nhight <= 1 and dist[nx][ny] == float('inf'):dist[nx][ny] = dist[x][y] + 1que.append((nx, ny))nx += iny += jif 0 <= nx < h and 0 <= ny < w:nhight = int(b[nx][ny])mhight = int(b[nx-i][ny-j])if mhight < hight == nhight and dist[nx][ny] == float('inf'):dist[nx][ny] = dist[x][y] + 1que.append((nx, ny))if dist[gx][gy] != float('inf'):print('YES')else:print('NO')