IOI '98 - Setúbal, Portugal
To brighten up the gala dinner of the IOI '98 we have a set of
- Button 1: When this button is pressed, all the lamps change their state: those that are ON are turned OFF and those that are OFF are turned ON.
- Button 2: Changes the state of all the odd numbered lamps.
- Button 3: Changes the state of all the even numbered lamps.
- Button 4: Changes the state of the lamps whose number is of the form
(with ), i.e.,
There is a counter
When the party starts, all the lamps are ON and the counter
You are given the value of counter
Input Specification
The input will have four lines, describing the number
- The first line contains the number
. - The second line contains the final value of counter
. - The third line lists the lamp numbers you are informed to be ON in
the final configuration, separated by one space and terminated by
the integer
. - The fourth line lists the lamp numbers you are informed to be OFF
in the final configuration, separated by one space and terminated by
the integer
.
Output Specification
The output must contain all the possible final configurations (without repetitions) of all the lamps. Each possible configuration must be written on a different line. Configurations may be listed in arbitrary order.
Each line has
If there are no possible configurations, output a single line with the
word IMPOSSIBLE
.
Sample Input
10
1
-1
7 -1
In this case, there are
Sample Output
0000000000
0110110110
0101010101
In this case, there are three possible final configurations:
- All lamps are OFF.
- Lamps
are OFF, and lamps are ON. - Lamps
are OFF, and lamps are ON.
Comments
I(somewhat a beginner) spent several hours to solve this, worth it.
ooo yes this was very satisfying to get