結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2020-09-12 13:07:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,530 bytes |
コンパイル時間 | 378 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 68,064 KB |
最終ジャッジ日時 | 2024-12-31 20:39:30 |
合計ジャッジ時間 | 2,789 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
h, w = map(int, input().split())sx, sy, gx, gy = map(int, input().split())B = [[int(i) for i in input()] for i in range(h)]visited = [[0] * w + [1, 1] for i in range(h)] + [[1] * (w + 2)] * 2from collections import dequeque = deque([sx - 1, sy - 1])visited[sx - 1][sy - 1] = 1while que:q1, q2 = que.popleft(), que.popleft()h = B[q1][q2]if visited[q1 + 1][q2] == 0 and abs(B[q1 + 1][q2] - h) < 2:visited[q1 + 1][q2] = 1que.extend([q1 + 1, q2])if visited[q1 - 1][q2] == 0 and abs(B[q1 - 1][q2] - h) < 2:visited[q1 - 1][q2] = 1que.extend([q1 - 1, q2])if visited[q1][q2 + 1] == 0 and abs(B[q1][q2 + 1] - h) < 2:visited[q1][q2 + 1] = 1que.extend([q1, q2 + 1])if visited[q1][q2 - 1] == 0 and abs(B[q1][q2 - 1] - h) < 2:visited[q1][q2 - 1] = 1que.extend([q1, q2 - 1])if visited[q1 + 2][q2] == 0 and B[q1 + 2][q2] == h and B[q1 + 1][q2] < h:visited[q1 + 2][q2] = 1que.extend([q1 + 2, q2])if visited[q1 - 2][q2] == 0 and B[q1 - 2][q2] == h and B[q1 - 1][q2] < h:visited[q1 - 2][q2] = 1que.extend([q1 - 2, q2])if visited[q1][q2 + 2] == 0 and B[q1][q2 + 2] == h and B[q1][q2 + 1] < h:visited[q1][q2 + 2] = 1que.extend([q1, q2 + 2])if visited[q1][q2 - 2] == 0 and B[q1][q2 - 2] == h and B[q1][q2 - 1] < h:visited[q1][q2 - 2] = 1que.extend([q1, q2 - 2])if visited[gx - 1][gy - 1]:print('YES')else:print('NO')