結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-24 12:05:02 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,417 bytes |
コンパイル時間 | 128 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-05 07:09:45 |
合計ジャッジ時間 | 1,989 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#!/usr/bin/env python3import collectionsDELTA_1 = [(1, 0), (-1, 0), (0, 1), (0, -1)]def can_escape(height, width, start, goal, stage):def out_of_stage(r, c):return r < 0 or r >= height or c < 0 or c >= widthvisited = collections.defaultdict(bool)visited[start] = Trueq = collections.deque()q.append(start)while q:r0, c0 = q.popleft()if (r0, c0) == goal:return Truefor dr, dc in DELTA_1:r, c = r0 + dr, c0 + dcif out_of_stage(r, c):continueelif abs(stage[r][c] - stage[r0][c0]) <= 1 and not visited[(r, c)]:visited[(r, c)] = Trueq.append((r, c))r2, c2 = r0 + 2 * dr, c0 + 2 * dcif out_of_stage(r2, c2):continueelif stage[r2][c2] == stage[r0][c0] > stage[r][c]:if not visited[(r2, c2)]:visited[(r2, c2)] = Trueq.append((r2, c2))else:return Falsedef main():height, width = map(int, input().split())sx, sy, gx, gy = map(lambda x: int(x) - 1, input().split())start = sx, sygoal = gx, gystage = [list(map(int, input())) for _ in range(height)]if can_escape(height, width, start, goal, stage):print("YES")else:print("NO")if __name__ == '__main__':main()