PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000142. Hoán vị đẹp (Pretty Permutations)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hoán vị đẹp (Pretty Permutations)
Pretty Permutations
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are cats in positions , initially with cat at position . Rearrange them so that no cat remains at its original position. If cat ends up at position , the total traveled distance is .
Output a permutation with no fixed points that minimizes this distance. Any optimal permutation is accepted.
Input
The input contains one integer .
Output
Print integers forming a permutation of , with and minimum total displacement.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
5
Output
2 1 4 5 3
Explanation
For , the permutation moves every cat. The total distance is , which is minimum for an odd number of cats.