Editorial for DMOPC '18 Contest 1 P3 - Sorting
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For the first subtask, any standard sorting algorithm is enough to score full points.
Number of operations:
For the second subtask, observe that the permutation can be modelled as a graph. Build an "edge" from each element
Number of operations:
For the final subtask, observe that the answer is always
If the permutation is initially sorted, the number of operations needed is
If the permutation consists of exactly
Suppose the permutation consists of
The first shift operation is
The second shift operation sorts each first element of each cycle after it was displaced in the first operation. So the second shift operation is
Number of operations:
Comments
Some people got 21 points on this problem by using
swaps to sort the array.