atcoder#ARC110F. [ARC110F] Esoswap
[ARC110F] Esoswap
Score : points
Problem Statement
We have a permutation of .
You can do the following operation on at most times:
- Announce an integer . Swap and .
Your task is to sort in ascending order with this operation.
If it is impossible, print -1
instead.
Constraints
- All values in input are integers.
- is a permutation of .
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to sort in ascending order with at most operations, print -1
.
Otherwise, print lines to represent a sequence of operations that sorts in ascending order, where is the number of operations done, as follows:
- The first line should contain the integer ;
- the -the line should contain the integer announced in the -th operation.
You do not have to minimize the number of operations done. If there are multiple such sequences of at most operations, any of them will be accepted.
8
7 1 2 6 4 0 5 3
4
6
0
3
0
This sequence of operations sorts in ascending order, as follows:
- First, announce . We swap and , turning into .
- Then, announce . We swap and , turning into .
- Then, announce . We swap and , turning into .
- Finally, announce . We swap and , turning into .