#C10542. Fuel-Constrained Space Navigation

    ID: 39759 Type: Default 1000ms 256MiB

Fuel-Constrained Space Navigation

Fuel-Constrained Space Navigation

In this problem, you are given a grid of size (n \times m) where each cell is either free (denoted by '.') or blocked by an obstacle (denoted by '#'). A spacecraft starts from the top-left cell at ( (0,0) ) and must reach the bottom-right cell at ( (n-1, m-1) ). The spacecraft has a fuel limit (f) which represents the maximum number of cells it can visit (including the starting cell). Your task is to determine whether the spacecraft can reach the destination cell without exceeding the fuel limit. You should output "YES" if it is possible and "NO" otherwise. Note that the movement is allowed in four directions: up, down, left, and right. (\newline)

Input and output are handled via standard input and standard output.

inputFormat

The first line of input contains three integers (n), (m), and (f) separated by spaces, where (n) is the number of rows and (m) is the number of columns in the grid, and (f) is the fuel limit (the maximum number of cells that can be visited). This is followed by (n) lines, each containing a string of length (m) that represents a row of the grid. Each character in the string is either '.' (a free cell) or '#' (an obstacle).

outputFormat

Output a single line containing "YES" if the spacecraft can reach the destination cell within the given fuel limit, or "NO" otherwise.## sample

3 3 5
...
.#.
...
YES