atcoder#ABC213E. [ABC213E] Stronger Takahashi
[ABC213E] Stronger Takahashi
Score : points
Problem Statement
There is a town divided into a grid of cells with rows and columns. The cell at the -th row from the top and -th column from the left is a passable space if is .
and a block if is #
.
Takahashi will go from his house to a fish market. His house is in the cell at the top-left corner, and the fish market is in the cell at the bottom-right corner.
Takahashi can move one cell up, down, left, or right to a passable cell. He cannot leave the town. He cannot enter a block, either. However, his physical strength allows him to destroy all blocks in a square region with cells of his choice with one punch, making these cells passable.
Find the minimum number of punches needed for Takahashi to reach the fish market.
Constraints
- and are integers.
- is
.
or#
. - and are
.
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5 5
..#..
#.#.#
##.##
#.#.#
..#..
1
He can reach the fish market by, for example, destroying the blocks in the square region with cells marked *
below.
..#..
#.**#
##**#
#.#.#
..#..
It is not required that all of the cells in the region to punch are blocks.
5 7
.......
######.
.......
.######
.......
0
He can reach the fish market without destroying blocks, though he has to go a long way around.
8 8
.#######
########
########
########
########
########
########
#######.
5