#D10372. Parity Sort
Parity Sort
Parity Sort
Problem statement
Given a permutation of length , sorted integers from to .
Sort in ascending order by doing the following up to .
operation
For operations, do the following 1 through 4 in sequence:
- Declare the string of length consisting of
0
and1
and the integer ( or ). - Prepare an empty sequence and do the following while moving the integer from to .
- When is
0
, do nothing. - When is
1
- If is even, add to the end of .
- If is odd, add to the end of .
- Define the sequence as follows.
- When , assumes that and are concatenated in this order.
- When , is the concatenation of and in this order.
- While moving the integer from to , do the following:
- When is
0
, do nothing. - When is
1
, replace with the first element of and delete the first element of .
For example, .
When is set to "1101101" and is set to , as shown in the figure below. I will.
parity-sort-example
Constraint
- is a permutation of integers from to
input
Input is given from standard input in the following format.
output
Output of the operation column that sorts in ascending order within in the following format. There may be multiple such operation sequences, but any output will be the correct answer.
- On the line, output for the number of operations to be performed. However, it must be .
- line is the integer declared in the th operation and the character in length. Output the column in this order.
Input example 1
7 0 4 2 3 6 5 1
Output example 1
1 1 0100101
When the operation is performed, , and from , .
Replacing the elements of with yields , so you can sort in ascending order with this operation. I will.
Input example 2
Four 1 0 3 2
Output example 2
2 0 1100 0 0011
For example, the following output is also a correct answer.
2 0 1111 1 0110
Input example 3
1 0
Output example 3
0
You do not have to perform any operation.
Example
Input
7 0 4 2 3 6 5 1
Output
1 1 0100101
inputFormat
input
Input is given from standard input in the following format.
outputFormat
output
Output of the operation column that sorts in ascending order within in the following format. There may be multiple such operation sequences, but any output will be the correct answer.
- On the line, output for the number of operations to be performed. However, it must be .
- line is the integer declared in the th operation and the character in length. Output the column in this order.
Input example 1
7 0 4 2 3 6 5 1
Output example 1
1 1 0100101
When the operation is performed, , and from , .
Replacing the elements of with yields , so you can sort in ascending order with this operation. I will.
Input example 2
Four 1 0 3 2
Output example 2
2 0 1100 0 0011
For example, the following output is also a correct answer.
2 0 1111 1 0110
Input example 3
1 0
Output example 3
0
You do not have to perform any operation.
Example
Input
7 0 4 2 3 6 5 1
Output
1 1 0100101
样例
7
0 4 2 3 6 5 1
1
1 0100101
</p>