#K58237. Path Existence in a Grid

    ID: 30598 Type: Default 1000ms 256MiB

Path Existence in a Grid

Path Existence in a Grid

You are given an \(n \times n\) grid where each cell is either empty, represented by a dot ('.'), or blocked, represented by a hash ('#'). You are also provided with the starting coordinates \((start\_x, start\_y)\) and ending coordinates \((end\_x, end\_y)\). Your task is to determine whether there exists a path from the starting point to the ending point using only horizontal and vertical moves without passing through any blocked cells.

Input Constraints:

  • \(1 \leq n \leq 1000\)
  • The grid consists exclusively of the characters '.' and '#'.
  • The start and end coordinates are within the bounds of the grid.

Note: Movement is allowed only in the four cardinal directions (up, down, left, right).

inputFormat

The first line contains an integer (n), the size of the grid. The next (n) lines each contain a string of length (n) representing the grid. The final line contains four integers: (start_x), (start_y), (end_x), (end_y), separated by spaces.

outputFormat

Output a single line: "YES" if there is a valid path from the starting point to the ending point, or "NO" if no such path exists.## sample

5
.....
..#..
.....
..#..
.....
0 0 4 4
YES