Corrupted Sort
시간 제한2초메모리 제한512 MB
클로이는 두 위치를 비교·교환하도록 요청할 수 있고 교환 여부만 들을 수 있지만, 2n번마다 코너가 몰래 임의의 두 카드를 바꿔 놓는다. 10000번 이하의 연산으로 카드를 정렬해야 한다.
문제
Chloe wants to test her sorting skills. She has cards with distinct integers from to written on them. She asks her little brother Connor to first blindfold her and then arrange all cards in a row in some order. Positions of cards are numbered from to from left to right.
Chloe doesn't know the order of the cards, but she wants to sort them, so that the leftmost card has number and the rightmost card has number on it. Formally, for each she wants the card on position to have number on it. To achieve the goal, Chloe can ask Connor to do one or more operations.
Each operation can be denoted by two integers and (). Connor looks at the cards on positions and , and if the card on position has a bigger number than the card on position , he swaps them. Otherwise, he does nothing. Connor also tells Chloe if he swapped the cards or not.
To make the game more interesting, after every operations Connor chooses two distinct cards uniformly at random and swaps them without telling anything to Chloe.
If after some of Chloe's operations all cards become sorted, Chloe wins. Help Chloe to sort all cards using at most operations.
힌트
Initial card ordering in the example was (that is, the card on position had number on it, the card on position had number , and the card on position had number ).