#K77757. Hiker's Grid Challenge

    ID: 34935 Type: Default 1000ms 256MiB

Hiker's Grid Challenge

Hiker's Grid Challenge

You are given a two-dimensional grid representing a hiking trail. The grid contains the following characters:

  • S represents the starting position of the hiker.
  • E represents the endpoint.
  • . represents an open cell that the hiker can traverse.
  • # represents an obstacle that cannot be crossed.

The hiker begins at S with an energy level E. Every move to one of the adjacent cells (up, down, left, or right) consumes 1 unit of energy. The goal is to determine whether there exists a path from S to E such that the total energy consumption does not exceed the available energy.

In formal terms, given integers \(M\), \(N\), and \(E\) where \(M\) is the number of grid rows, \(N\) is the number of grid columns, and \(E\) is the initial energy, you need to check if there is a path from the start to the endpoint where each move reduces energy by 1. The move cost is \(1\) (i.e., \(\Delta E = 1\) per move).

inputFormat

The input is provided via standard input. The first line contains three integers \(M\), \(N\), and \(E\) separated by spaces. \(M\) and \(N\) denote the number of rows and columns, respectively, and \(E\) is the initial energy level available to the hiker. This is followed by \(M\) lines, each consisting of a string of length \(N\) representing a grid row.

outputFormat

Output to standard output a single line containing YES if the endpoint can be reached within the available energy, or NO otherwise.

## sample
5 6 10
S.....
.###..
..#...
..####
...E..
YES