#P2130. 狂奔的Wzf

狂奔的Wzf

Description

There is a maze with nn rows and mm columns:

标识 含义
$ Empty cell, walkable.
. Also an empty cell, also walkable.
X Obstacle, not walkable.
# Goal; Wzf's homework is here.

Wzf starts from the top-left corner of the maze (row 11, column 11). Each second, it can:

  1. Choose a direction (up / down / left / right).
  2. Choose a non-negative integer mm.
  3. Take one step in the chosen direction, moving 2m2^m cells:
    • It must not cross any obstacle along the way.
    • The landing cell must not contain an obstacle.
    • It cannot go outside the maze.

Find the minimum number of seconds Wzf needs to reach the goal.

Input Format

The first line contains two integers n,mn, m with 1n,m10001 \le n, m \le 1000.

The next nn lines each contain mm characters.

It is guaranteed that there is exactly one #.

It is guaranteed that the cell at row 1\bm 1, column 1\bm 1 is not X.

Output Format

Output a single integer, the minimum number of seconds Wzf needs to reach the goal.

If Wzf cannot reach the goal, output 1-1.

2 2
$$
.#
2

Hint

Translated by ChatGPT 5