#P7693. [CEOI 2003] Shift Register
[CEOI 2003] Shift Register
Description
A computer register stores bits used for computations. A shift register is a special type of register whose bit values can be shifted by one position easily.
Using a feedback shift register, binary pseudo-random numbers can be generated as follows:
- A shift register of size is initially filled with bit values .
- Each time, the register outputs the value of its rightmost bit . All other bit values shift one position to the right. The first position is assigned a new value , as described below:
- Each bit of the register is connected to an XOR gate through a switch (see the figure below). For each bit , there is a switch (either or ) that decides whether the bit value is forwarded to the XOR gate.
- Let . The new value is set to the output of the XOR gate, i.e., .
- Note: If the number of 's among is odd, then , otherwise it is . The formal definition is:

In the example above, the first value is computed as follows: $\text{XOR}(1\cdot 1,0\cdot 0,1\cdot 1,1\cdot 1,0\cdot 0,1\cdot 0,1\cdot 1)=0$.
You are given the first output values of such a feedback shift register. From these values, you should try to determine the switch values .
Input Format
The first line contains an integer , the size of the shift register.
The second line contains digits 0 or 1, representing the first output bit values of the register.
Output Format
The output contains only one line.
- If there exists at least one switch setting that produces the given register output values, output a line of integers, where the -th integer is the value of switch . Any such switch setting will be accepted.
- If no such switch setting exists, output
-1.
7
1 0 0 1 1 0 1 0 1 1 0 0 1 1
1 0 1 1 0 1 1
3
0 0 0 1 1 1
-1
Hint
Constraints
For of the testdata, .
Notes
This problem comes from Shift Register of the CENTRAL-EUROPEAN OLYMPIAD IN INFORMATICS 2003.
Translated and organized by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号