Problem J
Matrix Keypad

When a button at row
Unfortunately, when multiple buttons are pressed at the same time, it may not be possible to uniquely identify which buttons are pressed. The only information you can have is this: for each wire, whether there is at least one button along that wire being pressed.
The software you are using to detect which buttons are
pressed was poorly implemented. After probing the keypad, it
stores the information in an
Your job is to interpret as much information from such a grid as possible. Determine which buttons are definitely pressed and which buttons are definitely not pressed.
Input
The first line of input contains a single positive integer
The remaining
Output
For each test case, output the following. If there is no combination of button presses on the keypad that would produce this 0/1 grid then simply output a line containing the word impossible
Otherwise, you should output
-
N if no button combination that produces the input grid has the
th button on row being pressed. -
P if all button combinations that produce the input grid have the
th button on row being pressed. -
I if some, but not all, button combinations that produce the input grid have the
th button on row being pressed.
Finally, the last line of each test case should be followed by the string ---------- (10 dashes).
Sample Input 1 | Sample Output 1 |
---|---|
3 4 3 110 000 110 000 2 3 101 000 2 2 10 01 |
IIN NNN IIN NNN ---------- PNP NNN ---------- impossible ---------- |