結果
| 問題 |
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 python3
import collections
DELTA_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 >= width
visited = collections.defaultdict(bool)
visited[start] = True
q = collections.deque()
q.append(start)
while q:
r0, c0 = q.popleft()
if (r0, c0) == goal:
return True
for dr, dc in DELTA_1:
r, c = r0 + dr, c0 + dc
if out_of_stage(r, c):
continue
elif abs(stage[r][c] - stage[r0][c0]) <= 1 and not visited[(r, c)]:
visited[(r, c)] = True
q.append((r, c))
r2, c2 = r0 + 2 * dr, c0 + 2 * dc
if out_of_stage(r2, c2):
continue
elif stage[r2][c2] == stage[r0][c0] > stage[r][c]:
if not visited[(r2, c2)]:
visited[(r2, c2)] = True
q.append((r2, c2))
else:
return False
def main():
height, width = map(int, input().split())
sx, sy, gx, gy = map(lambda x: int(x) - 1, input().split())
start = sx, sy
goal = gx, gy
stage = [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()
はむ吉🐹