CF1805A.We Need the Zero

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is an array aa consisting of non-negative integers. You can choose an integer xx and denote bi=ai⊕xb_i=a_i \oplus x for all 1≤i≤n1 \le i \le n, where ⊕\oplus denotes the bitwise XOR operation. Is it possible to choose such a number xx that the value of the expression b1⊕b2⊕…⊕bnb_1 \oplus b_2 \oplus \ldots \oplus b_n equals 00?

It can be shown that if a valid number xx exists, then there also exists xx such that (0≤x<280 \le x \lt 2^8).

有一个由非负整数构成的数组 aa。你可以选择一个整数 xx,并令对所有 1≤i≤n1 \le i \le n,有 bi=ai⊕xb_i = a_i \oplus x,其中 ⊕\oplus 表示按位异或运算。是否存在某个数 xx,使得表达式 b1⊕b2⊕…⊕bnb_1 \oplus b_2 \oplus \ldots \oplus b_n 的值等于 00?

可以证明:若存在满足条件的 xx,则必存在一个满足 0≤x<280 \le x < 2^8 的 xx。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The description of the test cases follows.

The first line of the test case contains one integer nn (1≤n≤1031 \le n \le 10^3) — the length of the array aa.

The second line of the test case contains nn integers — array aa (0≤ai<280 \le a_i \lt 2^8).

It is guaranteed that the sum of nn over all test cases does not exceed 10310^3.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1031 \le n \le 10^3)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数——数组 aa(0≤ai<280 \le a_i \lt 2^8)。

保证所有测试用例的 nn 之和不超过 10310^3。

输出格式

For each set test case, print the integer xx (0≤x<280 \le x \lt 2^8) if it exists, or −1-1 otherwise.

对于每组测试用例,如果存在满足条件的整数 xx(0≤x<280 \le x \lt 2^8),则输出该整数 xx;否则输出 −1-1。

输入输出样例

  • 输入#1

    5
    3
    1 2 5
    3
    1 2 3
    4
    0 1 2 3
    4
    1 2 2 3
    1
    1

    输出#1

    6
    0
    3
    -1
    1

说明/提示

In the first test case, after applying the operation with the number 66 the array bb becomes [7,4,3][7, 4, 3], 7⊕4⊕3=07 \oplus 4 \oplus 3 = 0.

There are other answers in the third test case, such as the number 00.

在第一个测试用例中,对数组 bb 应用数字 66 对应的操作后,数组变为 [7,4,3][7, 4, 3],且 7⊕4⊕3=07 \oplus 4 \oplus 3 = 0。

在第三个测试用例中还存在其他答案,例如数字 00。

输入解题思路,AI测评打分。不知道怎么写?

首页