| <p> |
| The 2019 Hacker Cup Finals have just concluded! There were <strong>N</strong> participants (numbered 1 to <strong>N</strong>), |
| including yourself (competing as participant 1), and <strong>M</strong> problems (numbered 1 to <strong>M</strong>). |
| </p> |
|
|
| <p> |
| Participant <em>i</em> solved problem <em>j</em> if <strong>S<sub>i,j</sub></strong> = "Y", and otherwise they didn't solve it (if <strong>S<sub>i,j</sub></strong> = "N"). |
| Problem <em>i</em>'s point value is 2<sup>i</sup>, and each participant's score is the sum of the point values of the problems that they solved. |
| No two participants solved exactly the same set of problems, which also means that all participants have distinct scores. |
| </p> |
|
|
| <p> |
| Before the final results get announced, you have an opportunity to rearrange the <strong>M</strong> columns of the scoreboard <strong>S</strong> |
| into any permutation of problems 1 to <strong>M</strong>. |
| For example, if you swap columns 1 and 2, then everybody who had originally solved problem 1 will now be considered to have solved problem 2 |
| (thus earning 4 points for it rather than 2), and vice versa. |
| </p> |
|
|
| <p> |
| Of course, you'd like to use this opportunity to your benefit — it would be irresponsible to just let it pass by! |
| However, it would be too suspicious if you simply made yourself win the whole competition. |
| As such, you'd like to cause yourself to end up in 2nd place, such that you (participant 1) have exactly the second-highest score out of all <strong>N</strong> participants. |
| Now you just need to determine whether or not this is achievable... |
| </p> |
|
|
|
|
| <h3>Input</h3> |
|
|
| <p> |
| Input begins with an integer <strong>T</strong>, the number of scoreboards. |
| <br />For each scoreboard, there is first a line containing the space-separated integers <strong>N</strong> and <strong>M</strong>. |
| <br />Then, <strong>N</strong> lines follow, the <em>i</em>th of which contains a length-<strong>M</strong> string, the characters |
| <strong>S<sub>i,1</sub></strong> through <strong>S<sub>i,M</sub></strong>. |
| </p> |
|
|
|
|
| <h3>Output</h3> |
|
|
| <p> |
| For the <em>i</em>th scoreboard, print a line containing "Case #<em>i</em>: " followed by |
| one character, either "Y" if you can end up in 2nd place, or "N" otherwise. |
| </p> |
|
|
|
|
| <h3>Constraints</h3> |
|
|
| <p> |
| 1 ≤ <strong>T</strong> ≤ 200 <br /> |
| 2 ≤ <strong>N</strong> ≤ 400 <br /> |
| 1 ≤ <strong>M</strong> ≤ 400 <br /> |
| </p> |
|
|
| <p> |
| The sum of <strong>N</strong> * <strong>M</strong> across all <strong>T</strong> test cases is no greater than 1,000,000. |
| </p> |
|
|
|
|
| <h3>Explanation of Sample</h3> |
|
|
| <p> |
| In the first case, there's only one possible permutation of problems: [1]. This results in you having a score of 2 and participant 2 having a score of 0, which puts you in 1st place rather than 2nd. |
| </p> |
|
|
| <p> |
| In the second case, if you preserve the original permutation of problems, [1, 2], you'll have a score of 2 while participant 2 has a score of 4, putting you in 2nd place, as required. |
| The permutation [2, 1] would have put you in 1st place instead. |
| </p> |
|
|
| <p> |
| In the third case, if you choose the problem permutation [2, 1], the 4 participants' scores will be 4, 0, 6, and 2, respectively. This puts you in 2nd place, as required. |
| The problem permutation [1, 2] would have put you in 3rd place instead. |
| </p> |
|
|
|
|