Problem C
Röðunarrugl
Languages
en
is
Input
The first line of the input contains a single integer $n$ satisfying $1 \leq n \leq 10^5$, the number of items to rearrange. Next there is a line with $n$ integers $k_1, k_2, \dots , k_ n$ satisfying $1 \leq k_ i \leq n$. The value $k_ i$ is the place the main character wants the item that is currently at location $i$ to be in. None of the $k_ i$ will equal $n + 1$ as that place should be empty at the end. The values will be unique as well.
Output
A single line with an integer giving the minimum number of moves needed to get everything to the desired place.
Scoring
Group |
Points |
Constraints |
1 |
20 |
$n \leq 5$ |
2 |
30 |
$n \leq 10^3$ |
3 |
50 |
No further constraints |
Sample Input 1 | Sample Output 1 |
---|---|
4 1 3 2 4 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
8 7 4 6 8 1 3 5 2 |
11 |