CF1362B.Johnny and His Hobbies

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble.

There is a set SS containing very important numbers on his dad's desk. The minute Johnny heard about it, he decided that it's a good idea to choose a positive integer kk and replace each element ss of the set SS with s⊕ks \oplus k (⊕\oplus denotes the exclusive or operation).

Help him choose such kk that Johnny's dad will not see any difference after his son is done playing (i.e. Johnny will get the same set as before playing). It is possible that no such number exists. It is also possible that there are many of them. In such a case, output the smallest one. Note that the order of elements in a set doesn't matter, i.e. set 1,2,3{1, 2, 3} equals to set 2,1,3{2, 1, 3}.

Formally, find the smallest positive integer kk such that s⊕k∣s∈S=S{s \oplus k | s \in S} = S or report that there is no such number.

For example, if S=1,3,4S = {1, 3, 4} and k=2k = 2, new set will be equal to 3,1,6{3, 1, 6}. If S=0,1,2,3S = {0, 1, 2, 3} and k=1k = 1, after playing set will stay the same.

在约翰尼众多的爱好中,有两个看似无害的:按位运算和偷偷溜进他爸爸的办公室。正如小孩子常有的情况一样,约翰尼并未意识到,将这两项活动结合起来可能会给他惹上大麻烦。

他爸爸的办公桌上放着一个集合 SS,其中包含一些非常重要的数字。约翰尼一听说这件事,就立刻决定:选择一个正整数 kk,并将集合 SS 中的每个元素 ss 替换为 s⊕ks \oplus k(其中 ⊕\oplus 表示异或运算)。

请帮助他选出这样的 kk,使得在他“玩完”之后,他爸爸看不出任何变化(即变换后得到的集合与原集合完全相同)。可能并不存在满足条件的数;也可能存在多个满足条件的数,此时请输出其中最小的一个。注意:集合中元素的顺序无关紧要,例如集合 {1,2,3}\{1, 2, 3\} 与 {2,1,3}\{2, 1, 3\} 是相等的。

形式化地说:请找出最小的正整数 kk,使得 {s⊕k∣s∈S}=S\{s \oplus k \mid s \in S\} = S;若不存在这样的 kk,则报告无解。

例如,若 S={1,3,4}S = \{1, 3, 4\} 且 k=2k = 2,则新集合为 {3,1,6}\{3, 1, 6\};若 S={0,1,2,3}S = \{0, 1, 2, 3\} 且 k=1k = 1,则变换后集合保持不变。

输入格式

In the first line of input, there is a single integer tt (1≤t≤10241 \leq t \leq 1024), the number of test cases. In the next lines, tt test cases follow. Each of them consists of two lines.

In the first line there is a single integer nn (1≤n≤10241 \leq n \leq 1024) denoting the number of elements in set SS. Second line consists of nn distinct integers sis_i (0≤si<10240 \leq s_i \lt 1024), elements of SS.

It is guaranteed that the sum of nn over all test cases will not exceed 10241024.

输入的第一行包含一个整数 tt(1≤t≤10241 \leq t \leq 1024),表示测试用例的数量。接下来的若干行包含 tt 个测试用例,每个测试用例由两行组成。

第一行包含一个整数 nn(1≤n≤10241 \leq n \leq 1024),表示集合 SS 中元素的个数。第二行包含 nn 个互不相同的整数 sis_i(0≤si<10240 \leq s_i \lt 1024),即集合 SS 的元素。

保证所有测试用例中 nn 的总和不超过 10241024。

输出格式

Print tt lines; ii-th line should contain the answer to the ii-th test case, the minimal positive integer kk satisfying the conditions or −1-1 if no such kk exists.

输出 tt 行;第 ii 行应包含第 ii 个测试用例的答案,即满足条件的最小正整数 kk;若不存在这样的 kk,则输出 −1-1。

输入输出样例

  • 输入#1

    6
    4
    1 0 2 3
    6
    10 7 14 8 3 12
    2
    0 2
    3
    1 2 3
    6
    1 4 6 10 11 12
    2
    0 1023

    输出#1

    1
    4
    2
    -1
    -1
    1023

说明/提示

In the first test case, the answer is 11 because it is a minimum positive integer and it satisfies all the conditions.

在第一个测试用例中,答案为 11,因为它是满足所有条件的最小正整数。

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

首页