#abc281f. F - Xor Minimization

F - Xor Minimization

Score : 500500 points

问题描述

给定一个非负整数序列 A=(a1,,aN)A=(a_1,\ldots,a_N)

现在,对序列 AA 执行以下操作仅一次:

  • 选择一个非负整数 xx。然后,对于所有 i=1,,Ni=1, \ldots, N,将 aia_i 的值替换为 aia_ixx 的按位异或结果。

MM 表示操作后 AA 中的最大值。找出 MM 可能达到的最小值。

什么是按位异或?非负整数 AABB 的按位异或(bitwise XOR)运算记作 ABA \oplus B,定义如下:

  • ABA \oplus B 以二进制表示时,第 kk 低位(k0k \geq 0)是 11,当且仅当 AABB 的第 kk 低位中恰好有一个是 11,否则该位为 00

例如:35=63 \oplus 5 = 6 (以二进制表示:011101=110011 \oplus 101 = 110)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence of non-negative integers A=(a1,,aN)A=(a_1,\ldots,a_N).

Let us perform the following operation on AA just once.

  • Choose a non-negative integer xx. Then, for every i=1,,Ni=1, \ldots, N, replace the value of aia_i with the bitwise XOR of aia_i and xx.

Let MM be the maximum value in AA after the operation. Find the minimum possible value of MM.

What is bitwise XOR? The bitwise XOR of non-negative integers AA and BB, ABA \oplus B, is defined as follows.

  • When ABA \oplus B is written in binary, the kk-th lowest bit (k0k \geq 0) is 11 if exactly one of the kk-th lowest bits of AA and BB is 11, and 00 otherwise.

For instance, 35=63 \oplus 5 = 6 (in binary: 011101=110011 \oplus 101 = 110).

Constraints

  • 1N1.5×1051 \leq N \leq 1.5 \times 10^5
  • 0ai<2300 \leq a_i \lt 2^{30}
  • All values in the input are integers.

Input

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

NN

a1a_1 \ldots aNa_N

Output

Print the answer.

Sample Input 1

3
12 18 11

Sample Output 1

16

If we do the operation with x=2x=2, the sequence becomes (122,182,112)=(14,16,9)(12 \oplus 2,18 \oplus 2, 11 \oplus 2) = (14,16,9), where the maximum value MM is 1616.
We cannot make MM smaller than 1616, so this value is the answer.

Sample Input 2

10
0 0 0 0 0 0 0 0 0 0

Sample Output 2

0

Sample Input 3

5
324097321 555675086 304655177 991244276 9980291

Sample Output 3

805306368

update @ 2024/3/10 11:48:48