아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Science Fiction

시간 제한2초메모리 제한512 MB

요약
n차원 하이퍼큐브의 2^n개 꼭짓점에 서로 다른 수가 주어질 때, 큐브의 모서리를 따라 교환해 꼭짓점 번호 순으로 수를 정렬하는 교환 열을 만든다.
난이도

보통10점 중 7점

유형
그리디, 그래프, 비트 연산, 구현
정답자
아직 제출이 없습니다

문제

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 2n 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 2n, 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 ⩽ i < 2n) is denoted by ai, you have to construct a sequence of valid pairwise swaps that makes the sequence a = ⟨a0, a1, ..., a2n−1⟩ in increasing order.

입력

The first line of input consists of n (1 ⩽ n ⩽ 10), the dimension of Dr. Khosro’s imaginary world. The next line contains 2n distinct integers, indicating a0, a1, ..., a2n−1 (0 ⩽ ai ⩽ 106).

출력

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

  1. 예제 1

    입력
    2
    3 2 10 4
    
    예상 출력
    2
    0 1
    2 3
    
  2. 예제 2

    입력
    1
    10 100
    
    예상 출력
    0