#C10569. Rabbit Rendezvous
Rabbit Rendezvous
Rabbit Rendezvous
Two rabbits live in a garden represented by an \(R \times C\) grid. Each cell in the grid is either empty (represented by a dot '.') or contains an obstacle (represented by a hash '#'). The rabbits can move upward, downward, leftward, or rightward, but they cannot enter cells that contain obstacles or move outside the grid boundaries.
Given the starting positions of the two rabbits (both 1-indexed), determine whether there exists a sequence of valid moves that allows the rabbits to meet on the same cell. If such a sequence exists, output YES; otherwise, output NO.
inputFormat
The input is provided via standard input (stdin) with the following format:
R C s1 s2 ... sR r1 c1 r2 c2
Where:
- R and C are integers representing the number of rows and columns of the garden.
- The next R lines each contain a string of length C representing a row of the garden. A character '.' denotes an empty cell and '#' denotes an obstacle.
- The next line contains two integers r1 and c1 which represent the starting row and column (1-indexed) of the first rabbit.
- The following line contains two integers r2 and c2 which represent the starting row and column (1-indexed) of the second rabbit.
outputFormat
The output is a single line written to standard output (stdout):
YES
if the rabbits can meet, or:
NO
if they cannot meet.
## sample4 4
....
.#..
..#.
....
1 1
4 4
YES