#K9031. Robot Navigation in a Grid

    ID: 37724 Type: Default 1000ms 256MiB

Robot Navigation in a Grid

Robot Navigation in a Grid

The problem describes a grid of size n × m where each cell is either an open space represented by . or an obstacle represented by #. A robot starts at the top-left cell (i.e. at position \( (0,0) \)) and needs to reach the bottom-right cell (i.e. \( (n-1, m-1) \)). The robot can move in four directions: up, down, left, and right. It cannot move through obstacles. Your task is to determine if there exists a valid path from the start to the goal.

inputFormat

The input is read from stdin and consists of multiple lines. The first line contains two integers n and m, which denote the number of rows and columns respectively. Each of the following n lines contains m space-separated characters (each either '.' or '#') representing the grid.

outputFormat

The output is printed to stdout. Print "YES" if a valid path exists from the top-left corner to the bottom-right corner, otherwise print "NO".## sample

4 4
. . . #
. # . .
. # # .
. . . .
YES