Conway
Time limit5sMemory limit512 MB
Roland and Patrick take turns toggling switch pairs wired to bulbs, and the task is to decide whether Roland can keep the lit bulbs' total power at least K.
- Level
Hard8 of 10
- Topics
- Game theory, Bit manipulation, Divide and conquer, Math
- Solved
- No attempts yet
Problem
There are light bulbs in a room and switches outside of it. is guaranteed to be odd. Each bulb has its own power and can only be fully on or fully off. If a bulb is on, it adds units to the illumination of the room.
Some switches and bulbs are connected by cords. Toggling a switch changes the state of every bulb connected to it. There are no restrictions on connections: any switch can be connected to any subset of bulbs, and the reverse also holds.
John invented a game and invited his friends Roland and Patrick to play it. Roland likes light and tries to make the illumination as high as possible. Patrick wants the opposite and tries to make it as low as possible. John chooses a value to decide the winner. When the game ends, if the total power of the bulbs that are on is at least , Roland wins. Otherwise, Patrick wins. The game proceeds as follows.
- Switches are numbered from 1 to .
- Each player makes exactly moves, alternating turns. Roland moves first.
- On his -th move, Roland can toggle switches and . On his first move these are switches 1 and 2, on his second move switches 3 and 4, and so on. He may toggle one of them, both, or neither. If a bulb is connected to both switches, its state changes once for each toggled switch.
- Patrick follows the same rules with different switches. On his -th move, he can toggle switches and . On his first move these are switches 2 and 3, on his second move switches 4 and 5, and so on.
John already knows the result of each game. Write a program that determines the winner of each of the games, assuming both Roland and Patrick play optimally.
Input
The first line contains the number of test cases (). Each test case describes one game.
The first line of each test case contains three integers , , and (, is odd, , ), where is the number of switches, is the number of bulbs, and is the illumination threshold.
The second line contains integers (), the power of each bulb.
The next lines each contain characters. If switch is connected to bulb , the -th character of the -th line is '1'. Otherwise it is '0'.
Output
For each test case, print one line with the winner, either "Roland" or "Patrick".
Hint
In the first game, one optimal strategy for Roland is to toggle switches 1 and 2 on his first turn. After any move by Patrick, exactly one bulb is on at the end, so Roland wins regardless.
In the second game, whatever Roland does, Patrick can turn off all the bulbs.