Logo
(追記) (追記ここまで)

19264번 - Hung Fu 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB37101045.455%

문제

The are two integer arrays $a$ and $b$ of length $n$. Consider the following formula:

$$\sum\limits_{i=1}^{n} \min\limits_{1 \leq j \leq i} a_i \oplus b_j\text{.}$$

You are practicing the calculation of the result of the above formula, and you have noticed that the order of elements in the arrays matters. Now you want to minimize the result of the calculation by permuting the elements of arrays $a$ and $b$. More formally, you want to find such a permutation $p$ that minimizes the following function:

$$F(p) = \sum\limits_{i=1}^{n} \min\limits_{1 \leq j \leq i} a_{p_i} \oplus b_{p_j}\text{.}$$

Find and output the lexicographically smallest permutation $p$ that minimizes the function.

입력

On the first line, you are given a single integer $n$: the size of arrays (1ドル \leq n \leq 50$).

On the second line, you are given $n$ integers $a_i$: the elements of array $a$ (0ドル \leq a_i \leq 1,000,000$).

On the third line, you are given $n$ integers $b_i$: the elements of array $b$ (0ドル \leq b_i \leq 1,000,000$).

출력

On the first line, output a single integer: the minimum possible result of the function. On the second line, output $n$ integers: the lexicographically smallest permutation $p$ that minimizes the result of the function.

제한

예제 입력 1

3
1 2 3
3 2 1

예제 출력 1

1
2 3 1

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2018 > Day 2: ITMO U 1 Contest H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /