#C2916. Minimum Moves Through Asteroids
Minimum Moves Through Asteroids
Minimum Moves Through Asteroids
You are given a grid of size \(n \times m\) where each cell is either empty (represented by .
) or contains an asteroid (represented by #
). Your task is to compute the minimum number of moves needed to travel from the top-left corner (cell \(1,1\)) to the bottom-right corner (cell \(n,m\)). You can only move either right or down at each step.
If it is not possible to reach the destination due to obstacles, output Impossible
.
Note: The starting and ending cells must be empty. Movement is only allowed to adjacent cells in the right or down direction.
inputFormat
The first line contains two positive integers \(n\) and \(m\) indicating the number of rows and columns, respectively. It is followed by \(n\) lines, each containing a string of \(m\) characters. Each character is either .
(empty) or #
(asteroid).
outputFormat
Output a single line. If a path to the destination exists, output the minimum number of moves required. Otherwise, output Impossible
.
4 4
....
.#..
.#..
....
6