Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2019 /round2 /on_the_run.md
wjomlex's picture
2019 Problems
e329daf verified
The world's funniest schoolteacher has found himself in some trouble. Or,
should we say, the world's funniest ex-schoolteacher. On the basis of a false
accusation regarding too many puns in his exam problems, Mr. X has not only
been fired, but is now on the run from the Humane Association for Humour
Administration (HAHA).
They've tracked Mr. X down to a yard in Scotland, which may be represented as
a grid with **N** rows (numbered 1 to **N**) and **M** columns (numbered 1 to
**M**). Mr. X is initially in row **A** and column **B**. There are also **K**
(1 ≤ **K** ≤ 2) HAHA agents hot on his trail, the _i_th of whom is initially
in row **Ri** and column **Ci**. All **K**+1 individuals are in distinct
cells.
The chase will then commence in an organized fashion as follows:
1. Each of the **K** HAHA agents in turn will move up, down, left, or right to an adjacent unoccupied cell* (without leaving the yard). The agents may choose to move in any order, but each of them must move exactly once, and multiple of them may not move simultaneously. It's guaranteed that all of the agents will always be able to move in some order for any possible state of the yard.
2. Mr. X will then attempt to similarly move to an adjacent unoccupied cell. If he's unable to move due to there being no unoccupied cells adjacent to him, he'll surrender quietly instead. Otherwise, the process will repeat from Step 1.
* _An unoccupied cell is one which currently contains neither Mr. X nor an agent._
Mr. X is hoping that, if he can avoid ever being forced to surrender, the HAHA
agents may eventually leave him alone, giving him the opportunity to slip away
and work on regaining his teaching position. However, the outcome of this
chase seems difficult to call. Assuming that the agents work together
optimally in an attempt to force Mr. X to surrender, while Mr. X optimally
chooses moves to avoid surrendering indefinitely, determine whether or not he
will eventually be forced to surrender.
### Input
Input begins with an integer **T**, the number of times that Mr. X is chased
by HAHA agents. For each chase, there is first a line containing the space-
separated integers **N**, **M**, and **K**. Then there is a line containing
the space-separated integers **A**, and **B**. Then, **K** lines follow, the
_i_th of which contains the space-separated integers **Ri** and **Ci**.
### Output
For the _i_th chase, print a line containing "Case #_i_: " followed by one
character, either "Y" if Mr. X will eventually be forced to surrender, or "N"
otherwise.
### Constraints
1 ≤ **T** ≤ 500
3 ≤ **N**, **M** ≤ 300
1 ≤ **K** ≤ 2
1 ≤ **A**, **Ri****N**
1 ≤ **B**, **Ci****M**
### Explanation of Sample
In the first case, no matter how much time goes by and what moves the HAHA
agent chooses to make, Mr. X can always avoid needing to surrender.
In the second case, if the first HAHA agent initially moves to cell (1, 2) and
the second agent moves to cell (2, 1), then Mr. X will immediately be forced
to surrender.