AAAA 1 P5 - Mirror Sort
View as PDFMirror Sort is an unconventional sorting algorithm which doesn't really sort an array. Rather, it performs a TЯOƧ to unorganize an array once more.
We begin with a sorted array of the integers to
, and the goal of the Mirror Sort algorithm is to convert this array into another given array,
with a sequence of reflections,
.
A reflection about a non-negative integer first decreases all elements in the array by
, then flips the sign of any resulting negative numbers to be positive. In other words, a reflection about the non-negative integer
updates every value
to
.
Can you find any sequence of reflections,
, which transforms the sorted array of integers
to
into the given array,
? If no such sequence exists, output
-1 instead.
For full points, must be less than or equal to
. You will receive 50% of the marks for a solution which satisfies
.
Constraints
Subtask 1 [80%]
Subtask 2 [20%]
No additional constraints.
Input Specification
The first line contains one integer, , the length of the array.
The next line contains space-separated integers,
, the target array.
Output Specification
If it is impossible to convert the sorted array of integers to
into the target array with a sequence of reflections, output
-1 on one line.
Otherwise, output one integer, , the number of reflections in your solution.
Then, on the next line, output integers in the inclusive range
separated by spaces,
, the sequence of reflections. If
, this line should be empty.
Scoring
If it is impossible to convert the sorted array of integers to
into the target array with a sequence of reflections, you will receive an Accepted verdict with full marks if you output
-1 on one line. Otherwise, you will receive a Wrong Answer verdict.
If it is possible to convert the sorted array of integers to
into the target array with a sequence of reflections, scoring will be done as follows:
If your outputted sequence of reflections does not convert the sorted array of integers to
into the target array or is formatted incorrectly, you will receive a Wrong Answer verdict.
If your outputted sequence of reflections correctly converts the sorted array of integers to
into the target array, your score will be determined by
:
If , you will receive a Wrong Answer verdict.
If , you will receive an Accepted verdict with 50% of the marks.
If , you will receive an Accepted verdict with full marks.
Your score for a subtask will be the minimum score over all testcases within the subtask.
Sample Input 1
5
2 3 2 1 0
Sample Output 1
2
2 3
Explanation for Sample 1
We begin with the array .
After performing a reflection about the value , the resulting array is
.
Finally, performing a reflection about the value results in
, which is the desired target array.
Since we have found a valid sequence of reflections, and
, this sample output will receive full points.
Sample Input 2
2
1 1
Sample Output 2
-1
Explanation for Sample 2
It can be shown that it is not possible to convert the array into the target array
with a sequence of reflections.
Comments