結果
問題 | No.424 立体迷路 |
ユーザー |
👑 |
提出日時 | 2022-02-14 00:23:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 914 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 66,176 KB |
最終ジャッジ日時 | 2024-06-29 05:52:16 |
合計ジャッジ時間 | 2,289 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
h, w = map(int, input().split())sx, sy, gx, gy = map(int, input().split())sx -= 1sy -= 1gx -= 1gy -= 1B = [list(map(int, input())) for _ in range(h)]tf = [[False] * w for _ in range(h)]tf[sx][sy] = Truestack = [(sx, sy)]directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]while stack:x, y = stack.pop()for dx, dy in directions:nx = x + dxny = y + dyif nx == -1 or nx == h or ny == -1 or ny == w:continueif abs(B[x][y] - B[nx][ny]) <= 1 and not tf[nx][ny]:tf[nx][ny] = Truestack.append((nx, ny))nx2 = nx + dxny2 = ny + dyif nx2 == -1 or nx2 == h or ny2 == -1 or ny2 == w:continueif B[x][y] == B[nx2][ny2] and B[nx][ny] < B[x][y] and not tf[nx2][ny2]:tf[nx2][ny2] = Truestack.append((nx2, ny2))if tf[gx][gy]:print("YES")else:print("NO")