- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Arts and literature have always been influenced by science. This appears, for example, in Christopher Nolan movies. But, there is a scientist who is doing his research on a hypothesis based on fictional novels.
Dr. Khosro, a theoretical physicist, does research on parallel worlds with high-dimensions, inspired by Isaac Asimov’s novels. During his research, he needs a method of sorting in his imaginary high-dimension network of planets. In Dr. Khosro’s imaginary n-dimensional world, there are \(2^n\) planets and a wormhole network connecting them. The network is like an \(n\)-dimensional hypercube. The planets are numbered with non-negative integers less than \(2^n\), and there is a wormhole from planet a to planet b if and only if the n-bit binary representations of \(a\) and \(b\) differ in exactly one bit-position. In Dr. Khosro’s model, there is a number written on each planet and we can swap the numbers of two planets only if there is a direct wormhole between them. You are given the numbers written on each planet, construct a valid sequence of swaps that makes the numbers sequence sorted from smallest to largest. Formally, if the number written on the planet number \(i\) (\(0 \leq i \lt 2^n\)) is denoted by \(a_i\), you have to construct a sequence of valid pairwise swaps that makes the sequence \(a = \langle a_0, a_1, \dots, a_{2^{n-1}} \rangle\) in increasing order.
ورودی
The first line of input consists of \(n\) (\(1 \leq n \leq 10\)), the dimension of Dr. Khosro’s imaginary world. The next line contains \(2^n\) distinct integers, indicating \(a_0, a_1, \dots, a_{2^{n-1}} \; (0 \leq a_i \leq 10^6)\).
خروجی
Print the numbers of your swaps in the first line. Your answer will be considered correct if this number is nonnegative and less than \(12,000\). Then in the following lines, print the sequence of swaps. In your solution, every swap must be between two planets with a direct wormhole between them.
مثالها
ورودی نمونه ۱
2
3 2 10 4
خروجی نمونه ۱
2
1 0
3 2
ورودی نمونه ۲
1
10 100
خروجی نمونه ۲
0
ارسال پاسخ برای این سؤال