結果
| 問題 | 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 -= 1
sy -= 1
gx -= 1
gy -= 1
B = [list(map(int, input())) for _ in range(h)]
tf = [[False] * w for _ in range(h)]
tf[sx][sy] = True
stack = [(sx, sy)]
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
while stack:
x, y = stack.pop()
for dx, dy in directions:
nx = x + dx
ny = y + dy
if nx == -1 or nx == h or ny == -1 or ny == w:
continue
if abs(B[x][y] - B[nx][ny]) <= 1 and not tf[nx][ny]:
tf[nx][ny] = True
stack.append((nx, ny))
nx2 = nx + dx
ny2 = ny + dy
if nx2 == -1 or nx2 == h or ny2 == -1 or ny2 == w:
continue
if B[x][y] == B[nx2][ny2] and B[nx][ny] < B[x][y] and not tf[nx2][ny2]:
tf[nx2][ny2] = True
stack.append((nx2, ny2))
if tf[gx][gy]:
print("YES")
else:
print("NO")