#P7693. [CEOI 2003] Shift Register

[CEOI 2003] Shift Register

Description

A computer register stores NN 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 NN is initially filled with bit values a1,a2,,aNa_1,a_2,\cdots,a_N.
  • Each time, the register outputs the value of its rightmost bit aNa_N. All other bit values shift one position to the right. The first position is assigned a new value a1a_1^{\prime}, as described below:
    • Each bit of the register is connected to an XOR gate through a switch (see the figure below). For each bit ii, there is a switch sis_i (either 11 or 00) that decides whether the bit value aia_i is forwarded to the XOR gate.
    • Let ki=siaik_i=s_i\cdot a_i. The new value a1a_1^{\prime} is set to the output of the XOR gate, i.e., XOR(k1,,kN)\text{XOR}(k_1,\cdots, k_N).
  • Note: If the number of 11's among k1,,kNk_1,\cdots,k_N is odd, then XOR(k1,,kN)=1\text{XOR}(k_1,\cdots,k_N)=1, otherwise it is 00. The formal definition is:
a1=XOR(k1,,kN)a_1^{\prime}=XOR(k_1,\cdots,k_N) ai=ai1 for 2iNa_i^{\prime}=a_{i−1}\ \text{for}\ 2\le i\le N output=aN\text{output}=a_N

TuLi

In the example above, the first value a1a_1^{\prime} 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 2N2N output values of such a feedback shift register. From these values, you should try to determine the switch values sis_i.

Input Format

The first line contains an integer NN, the size of the shift register.

The second line contains 2N2N digits 0 or 1, representing the first 2N2N 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 NN integers, where the ii-th integer is the value of switch sis_i. 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 100%100\% of the testdata, 1N7501\le N\le 750.

Notes

This problem comes from Shift Register of the CENTRAL-EUROPEAN OLYMPIAD IN INFORMATICS 2003.

Translated and organized by @求学的企鹅.

Translated by ChatGPT 5