QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100

#11616. 鸿福

统计

有两个长度为 $n$ 的整数数组 $a$ 和 $b$。考虑以下公式:

$$\sum_{i=1}^{n} \min_{1 \le j \le i} a_i \oplus b_j$$

你正在练习计算上述公式的结果,并注意到数组中元素的顺序很重要。现在,你希望通过对数组 $a$ 和 $b$ 的元素进行排列来最小化计算结果。更正式地说,你想要找到一个排列 $p$,使得以下函数最小化:

$$F(p) = \sum_{i=1}^{n} \min_{1 \le j \le i} a_{p_i} \oplus b_{p_j}$$

请找到并输出使该函数最小化的字典序最小的排列 $p$。

输入格式

第一行包含一个整数 $n$:数组的大小 ($1 \le n \le 50$)。 第二行包含 $n$ 个整数 $a_i$:数组 $a$ 的元素 ($0 \le a_i \le 1,000,000$)。 第三行包含 $n$ 个整数 $b_i$:数组 $b$ 的元素 ($0 \le b_i \le 1,000,000$)。

输出格式

第一行输出一个整数:函数的最小可能结果。 第二行输出 $n$ 个整数:使函数结果最小化的字典序最小的排列 $p$。

样例

输入 1

3
1 2 3
3 2 1

输出 1

1
2 3 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.