P7262 Get Your Wish
Background

> So, tell me how it felt when you walked on water
>
> Did you get your wish?
Description
Porter finished his MV in shallow water, but he soon realized something was wrong: his microphone got water inside.
The key electronic components inside Porter’s microphone can be viewed as an $n \times m$ 2D grid. We use an $n \times m$ ASCII map to describe the inside of the microphone, where there are three kinds of characters:
- `.`: an empty cell.
- `x`: a key electronic component.
- `o`: a water droplet.
A water droplet will keep flowing along the direction of gravity until it either flows out of the boundary or flows onto an electronic component. If any droplet flows onto any electronic component, Porter’s microphone will break. Porter hurriedly flips the microphone over, changing the direction of gravity inside it. The gravity direction is given by one of the four characters `^v`, which correspond to up, down, left, and right.
Porter wants to know whether, under this gravity direction, his microphone will become GG after a while.
Input Format
The first line contains two positive integers and one character, representing $n$, $m$, and the gravity direction.
The next $n$ lines each contain $m$ characters, describing the state of each cell.
Output Format
Output one line with one string. `GG` means Porter’s microphone will break, and `OK` means it will not.
Explanation/Hint
### Sample Explanation
Sample 1: The droplet in the first row, second column flows downward to the electronic component in the last row, second column, so the microphone breaks.
Sample 2: The droplet in the second row, first column flows rightward to the electronic component in the second row, last column, so the microphone breaks.
Sample 3: The droplet in the first row, second column flows upward and directly out of the microphone, so Porter’s microphone will not break.
### Constraints
For all testdata, $1 \le n, m \le 100$, and the input is guaranteed to be valid.
Subtask 1 (10 pts): There is no `x` (electronic component) in the microphone.
Subtask 2 (10 pts): There is no `o` (water droplet) in the microphone.
Subtask 3 (30 pts): The gravity direction is always `v` (downward).
Subtask 4 (50 pts): No special restrictions.
Translated by ChatGPT 5