#C7194. Watering Plants in the Garden
Watering Plants in the Garden
Watering Plants in the Garden
Emily owns a beautiful garden represented as a grid with N rows and M columns. Each cell in the grid is one of the following:
- E for an empty cell,
- P for a plant, or
- S for a sprinkler.
A plant is considered watered if there is at least one sprinkler in the same row or column such that no other plant obstructs the path between them. In other words, for a plant located at \( (i,j) \), check in the four directions. A sprinkler in a direction waters the plant if all cells between the plant and that sprinkler (exclusively) do not contain another plant. Formally, if a sprinkler is found in a direction before any other plant, the plant is watered.
Your task is to determine whether every plant in the garden is watered by at least one sprinkler. If all plants are watered, output "Yes"; otherwise, output "No".
Note: The grid indices and directions follow the usual matrix conventions.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains two space-separated integers \( N \) and \( M \) representing the number of rows and columns of the grid respectively.
- Each of the following \( N \) lines contains a string of length \( M \) representing a row of the grid. Each character is either 'E', 'P', or 'S'.
outputFormat
Output a single line to standard output (stdout) containing "Yes" if every plant is watered by at least one sprinkler; otherwise, output "No".
## sample4 4
EPEE
SSPE
EPPS
EEEE
Yes