結果
| 問題 | 
                            No.424 立体迷路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-08-28 16:47:25 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,006 bytes | 
| コンパイル時間 | 447 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 69,504 KB | 
| 最終ジャッジ日時 | 2024-12-29 22:03:54 | 
| 合計ジャッジ時間 | 2,895 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 19 WA * 2 | 
ソースコード
from collections import deque
h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1
b = [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] = 0
que = deque([(sx, sy)])
while que:
    x, y = que.popleft()
    hight = int(b[x][y])
    for i, j in way:
        nx = x + i
        ny = y + j
        if 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] + 1
                que.append((nx, ny))
        nx += i
        ny += j
        if 0 <= nx < h and 0 <= ny < w:
            nhight = int(b[nx][ny])
            if hight == nhight and dist[nx][ny] == float('inf'):
                dist[nx][ny] = dist[x][y] + 1
                que.append((nx, ny))
if dist[gx][gy] != float('inf'):
    print('YES')
else:
    print('NO')