#K54892. Taco Grid Path

    ID: 29854 Type: Default 1000ms 256MiB

Taco Grid Path

Taco Grid Path

You are given a grid with n rows and m columns, where each cell is either an open space represented by '0' or an obstacle represented by '1'. Starting from the top-left corner (0,0), your goal is to reach the bottom-right corner (n-1, m-1) by moving in the four cardinal directions (up, down, left, and right).

The distance of a path is defined as the number of moves taken. You are also given an integer k. Your task is to determine whether there exists a valid path from the start to the destination such that the total number of moves does not exceed k. In mathematical terms, if the minimum distance d between the start and the destination satisfies $$ d \leq k, $$ then print YES; otherwise, print NO.

Note: The starting cell and the destination cell must both be open (i.e. '0').

inputFormat

The first line contains three integers n, m, and k separated by spaces, where:

  • n - the number of rows in the grid
  • m - the number of columns in the grid
  • k - the maximum allowed number of moves

The next n lines each contain a string of length m consisting of characters '0' and '1', representing the grid.

outputFormat

Output a single line containing either YES if there exists a path from the start to the destination with a number of moves at most k, or NO otherwise.

## sample
5 5 10
00000
01110
01110
01110
00000
YES