|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||7||2||2||28.571%|
You own several hats, some of which you wear more than others. Because wearing all n at once would be impractical, you store the spares on a rack with n − 1 hooks. The first hook is a half metre from the door, the second one metre, the third a metre-and-a-half, and so on. This means that walking from and to the door to the ith hook involves i metres of walking.
Tonight you will need to make a series of public appearances, each time wearing headgear appropriate to the role. When you come back from one engagement, you will take the hat you need from its hook and exchange it with the one you had been wearing before. This means that hats can move around as the night goes on.
Given the plan for tonight, and assuming you are already wearing the first one, what is the best way to arrange the hats on the rack before setting off so as to minimise the number of metres walked?
Output the minimum number of metres you need to walk, once you have optimised your hat rack.
Next, output c − 1 integers: an initial ordering of the hat rack that gives minimum walking distance, starting from place 1. This should include exactly once every hat except the first.
If there are multiple correct answers, you may output any one of them.
3 5 1 3 2 3 2
5 2 3
5 9 1 4 2 3 5 2 5 2 5
14 3 5 4 2