Dilhan's Computing Contest 1 P6 - Subsequence Reversal

View as PDF

Submit solution

Points: 35 (partial)
Time limit: 4.0s
Memory limit: 1G

Author:
Problem type

In Ethan's room, he keeps his prized permutation p of the integers from 1 to N in sorted order.
Unfortunately last night he forgot to close the door of his pet birds' cages. While he slept, the birds have escaped and shuffled p!

Luckily, Ethan has figured out a way to get the birds to restore p to its sorted state. In a given instruction, Ethan can direct k \geq 0 birds to each pick up an element of p, and then get the birds to reverse their order. In particular, the leftmost bird will swap with the rightmost bird and so on down the order.
More formally Ethan can select k integers 1 \leq x_1 < x_2 < \dots < x_k \leq n, and the following assignments all occur simultaneously:

\displaystyle p_{x_1} := p_{x_k}, p_{x_2} := p_{x_{k-1}}, p_{x_3} := p_{x_{k-2}}, \dots, p_{x_{k-1}} := p_{x_2}, p_{x_k} := p_{x_1}

Our goal is to sort the permutation into increasing order using repeated instructions given to the birds.
However, it's unclear how long Ethan can get the birds to listen to his instructions. As such, try to minimize the maximum number of instructions that Ethan will have to give.

Constraints

1 \leq N \leq 10^5

1\leq p_i \leq N

It is guaranteed that the p_i will form a permutation.

Subtask 1 [50%]

N is a power of two.

Subtask 2 [15%]

N \leq 90\ 000

Subtask 3 [10%]

N = 10^5

Subtask 4 [25%]

No additional constraints.

Scoring

Let M be the maximum number of operations used in any test-case in a subtask.

For each subtask, the following table denotes the percentage of the total value of that subtask your solution will recieve:

MScore (Subtask 1)Score (Other Subtasks)
M \leq 31100100
M = 329070
33 \leq M \leq 50 87 - (M - 33)51 - 3(M - 33)
50 < M \leq 200 70 - \left\lfloor\frac{M - 50}{6}\right\rfloor0
200 < M \leq 69545 - \left\lfloor\frac{M - 200}{11}\right\rfloor0
M > 69500

Input Specification

The first line of input consists of a single integer N.

The second line of each test case contains N integers p_1, p_2 \dots , p_N: the permutation to sort.

Output Specification

The first line of output contains a single integer M: the number of operations you used.

Then follow M lines of output.

The i+1-st line of output contains a binary string of length N: s_i.

If the j-th character of s_i is 1, then j is an index in the i-th operation (and the opposite if the j-th character is 0).

Sample Input 1

4
1 3 4 2

Sample Output 1

4
1110
0100
0011
1111

Sample Explanation 1

After the first operation, the permutation is 4 3 1 2.

After the second operation, the permutation is 4 3 1 2.

After the third operation, the permutation is 4 3 2 1.

After the fourth operation, the permutation is 1 2 3 4 --- sorted order.

Sample Input 2

8
1 2 3 4 5 6 7 8

Sample Output 2

0

Note

If your output contains more than 800 operations you may get a verdict of Output Limit Exceeded instead of the expected 0 point partial.


Comments

There are no comments at the moment.