結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2018-05-26 12:11:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 854 bytes |
コンパイル時間 | 119 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-07-05 07:16:00 |
合計ジャッジ時間 | 1,860 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
from collections import dequeH, W = map(int, input().split())sy, sx, gy, gx = map(int, input().split())inf = float("inf")b = [[inf]+list(map(int, input()))+[inf] for _ in [0]*H]b = [[inf]*(W+2)] + b + [[inf]*(W+2)]visited = [[0]*(W+2) for _ in [0]*(H+2)]visited[sy][sx] = 1dq = deque([(sx, sy, b[sy][sx])])popleft, append = dq.popleft, dq.appendwhile dq:x, y, h = popleft()if x == gx and y == gy:print("YES")exit()for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0)):nx, ny = x+dx, y+dyh2 = b[ny][nx]if abs(h-h2) <= 1 and visited[ny][nx] == 0:visited[ny][nx] = 1append((nx, ny, h2))if h > h2 and b[ny+dy][nx+dx] == h and visited[ny+dy][nx+dx] == 0:visited[ny+dy][nx+dx] = 1append((nx+dx, ny+dy, b[ny+dy][nx+dx]))print("NO")