#P1468. [IOI 1998 / USACO2.2] 派对灯 Party Lamps
[IOI 1998 / USACO2.2] 派对灯 Party Lamps
Description
At the IOI 1998 holiday banquet, we have colored lamps, numbered from 1 to . These lamps are connected to four buttons:
- Button : When pressed, it toggles all lamps: lamps that are on turn off, and lamps that are off turn on.
- Button : When pressed, it toggles all lamps with odd indices.
- Button : When pressed, it toggles all lamps with even indices.
- Button : When pressed, it toggles all lamps whose indices are . For example: 1, 4, 7, 10, …
A counter records how many times buttons have been pressed. When the banquet starts, all lamps are on, and the counter is 0.
You are given the value on the counter and the final states of some lamps after several operations. Write a program to find all possible final states of the lamps that are consistent with the given information, without duplicates.
Input Format
The first line contains a positive integer .
The second line contains an integer , the final value of the counter.
The third line contains several integers, indicating the lamps that are on in the end, terminated by -1.
The fourth line contains several integers, indicating the lamps that are off in the end, terminated by -1.
It is guaranteed that no lamp appears twice in the input.
Output Format
Each line contains one possible final state of all lamps (without duplicates).
Each line has characters. The -th character corresponds to lamp . 0 means off, and 1 means on. These lines must be sorted from small to large when viewed as binary numbers.
If there is no possible state, output a single line IMPOSSIBLE.
10
1
-1
7 -1
0000000000
0101010101
0110110110
Hint
Constraints
For of the testdata, , .
Sample explanation
In this sample, there are three possible states:
- All lamps are off.
- Lamps 1, 4, 7, 10 are off; 2, 3, 5, 6, 8, 9 are on.
- Lamps 1, 3, 5, 7, 9 are off; 2, 4, 6, 8, 10 are on.
Translation from NOCOW.
Translated by ChatGPT 5
京公网安备 11011102002149号