103046: [Atcoder]ABC304 G - Max of Medians

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $625$ points

Problem Statement

You are given a sequence of length $2N$: $A = (A_1, A_2, \ldots, A_{2N})$.

Find the maximum value that can be obtained as the median of the length-$N$ sequence $(A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N})$ by rearranging the elements of the sequence $A$.

Here, $\oplus$ represents bitwise exclusive OR.

What is bitwise exclusive OR? The bitwise exclusive OR of non-negative integers $A$ and $B$, denoted as $A \oplus B$, is defined as follows:
  • The number at the $2^k$ position ($k \geq 0$) in the binary representation of $A \oplus B$ is $1$ if and only if exactly one of the numbers at the $2^k$ position in the binary representation of $A$ and $B$ is $1$, and it is $0$ otherwise.
For example, $3 \oplus 5 = 6$ (in binary notation: $011 \oplus 101 = 110$).

Also, for a sequence $B$ of length $L$, the median of $B$ is the value at the $\lfloor \frac{L}{2} \rfloor + 1$-th position of the sequence $B'$ obtained by sorting $B$ in ascending order.

Constraints

  • $1 \leq N \leq 10^5$
  • $0 \leq A_i < 2^{30}$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_{2N}$

Output

Print the answer.


Sample Input 1

4
4 0 0 11 2 7 9 5

Sample Output 1

14

By rearranging $A$ as $(5, 0, 9, 7, 11, 4, 0, 2)$, we get $(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) = (5, 14, 15, 2)$, and the median of this sequence is $14$.
It is impossible to rearrange $A$ so that the median of $(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8)$ is $15$ or greater, so we print $14$.


Sample Input 2

1
998244353 1000000007

Sample Output 2

1755654

Sample Input 3

5
1 2 4 8 16 32 64 128 256 512

Sample Output 3

192

Input

题意翻译

给定一个长度为 $2N(1\le N\le 10^5)$ 的序列 $\{A_i\}(0\le A_i< 2^{30})$,你需要将其中元素两两配对并求异或和,得到 $N$ 个数的集合 $B$。最大化 $B$ 的中位数,其中集合的中位数定义为将集合排序后得到序列的第 $\lfloor\dfrac N2\rfloor + 1$ 项。

Output

得分:625分 部分 问题描述 给定一个长度为$2N$的序列$A=(A_1, A_2, \ldots, A_{2N})$。 重新排列序列$A$的元素,找到作为序列$(A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N})$中位数的最大可能值。在这里,$\oplus$表示按位异或。
什么是按位异或?非负整数$A$和$B$的按位异或,表示为$A \oplus B$,定义如下: 在$A \oplus B$的二进制表示中的第$2^k$位($k \geq 0$)是$1$,当且仅当$A$和$B$的二进制表示中的第$2^k$位中有一个是$1$,而另一个是$0$。否则,它为$0$。 例如,$3 \oplus 5 = 6$(在二进制表示中:$011 \oplus 101 = 110$)。
此外,对于长度为$L$的序列$B$,$B$的中位数是将$B$按升序排序后得到的序列$B'$的第$\lfloor \frac{L}{2} \rfloor + 1$位的值。 部分 约束 * $1 \leq N \leq 10^5$ * $0 \leq A_i < 2^{30}$ * 所有输入值都是整数。 部分 输入 输入是按以下格式从标准输入给出的: $N$ $A_1$ $A_2$ $\ldots$ $A_{2N}$ 部分 输出 打印答案。 部分 样例输入 1 ``` 4 4 0 0 11 2 7 9 5 ``` 部分 样例输出 1 ``` 14 ``` 通过重新排列$A$为$(5, 0, 9, 7, 11, 4, 0, 2)$,我们得到$(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) = (5, 14, 15, 2)$,该序列的中位数为14。 无法重新排列$A$,使得$(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8)$的中位数为15或更大,因此我们打印14。 部分 样例输入 2 ``` 1 998244353 1000000007 ``` 部分 样例输出 2 ``` 1755654 ``` 部分 样例输入 3 ``` 5 1 2 4 8 16 32 64 128 256 512 ``` 部分 样例输出 3 ``` 192 ```

加入题单

算法标签: