結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-03 01:26:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 1,431 bytes |
| コンパイル時間 | 390 ms |
| コンパイル使用メモリ | 82,044 KB |
| 実行使用メモリ | 68,208 KB |
| 最終ジャッジ日時 | 2024-07-03 01:27:01 |
| 合計ジャッジ時間 | 2,685 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
# https://yukicoder.me/problems/no/1219
from collections import deque
def main():
h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
B = []
for _ in range(h):
row = input()
row = [int(x) for x in row]
B.append(row)
sx -= 1
sy -= 1
gx -= 1
gy -= 1
dists = [[False] * w for _ in range(h)]
dists[sx][sy] = True
queue = deque()
queue.append((sx, sy))
while len(queue) > 0:
x, y = queue.popleft()
height = B[x][y]
for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
nx = x + dx
ny = y + dy
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
if abs(B[nx][ny] - height) <= 1 and dists[nx][ny] == False:
dists[nx][ny] = True
queue.append((nx, ny))
for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
nx = x + 2 * dx
ny = y + 2 * dy
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
nx1 = x + dx
ny1 = y + dy
if height == B[nx][ny] and B[nx1][ny1] < height:
if dists[nx][ny] == False:
dists[nx][ny] = True
queue.append((nx, ny))
if dists[gx][gy]:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()