Success
Time limit2sMemory limit512 MB
Find the fewest D by D blasts needed to clear obstacles so a path of open cells exists from the top-left to the bottom-right of an N by M grid.
- Level
Medium6 of 10
- Topics
- BFS, Shortest path, Matrix
- Solved
- No attempts yet
Problem
The road to success is never smooth. Obstacles fill it, and you can get stuck and stop right where you are. So you want to blow them up.
The road to success lies on an grid. To succeed, start at the top-left cell, step only onto cells without obstacles that are adjacent up, down, left, or right, and reach the bottom-right cell. One blast operation can remove every obstacle inside a subgrid. Blasting takes a lot of effort, so find the minimum number of blasts needed to succeed.
Input
The first line contains the number of rows , the number of columns , and the blast range (, , ). Next, lines follow, each a string of length describing one row of the grid. "." is a cell without an obstacle, and "#" is a cell with an obstacle. The start and the goal cells have no obstacles.
Output
Print the minimum number of blast operations on the first line.
Hint
