#P16742. [GKS 2019 #G] The Equation

    ID: 16990 Type: RemoteJudge 3000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>贪心2019位运算Google Kick Start

[GKS 2019 #G] The Equation

题目描述

The laws of the universe can be represented by an array of NN non-negative integers. The i-th of these integers is AiA_i.

The universe is good if there is a non-negative integer kk such that the following equation is satisfied: $(A_1 \text{ xor } k) + (A_2 \text{ xor } k) + ... (A_N \text{ xor } k) \le M$, where xor denotes the bitwise exclusive or.

What is the largest value of kk for which the universe is good?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing the two integers NN and MM, the number of integers in AA and the limit on the equation, respectively.

The second line contains NN integers, the i-th of which is AiA_i, the i-th integer in the array.

输出格式

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the largest value of k for which the universe is good, or −1-1 if there is no such kk.

4
3 27
8 2 4
4 45
30 0 4 11
1 0
100
6 2
5 5 1 5 1 0
Case #1: 12
Case #2: 14
Case #3: 100
Case #4: -1

提示

In sample case #1, the array contains N=3N = 3 integers and M=27M = 27. The largest possible value of kk that gives a good universe is 1212 ($(8 \text{ xor } 12) + (2 \text{ xor } 12) + (4 \text{ xor } 12) = 26$).

In sample case #2, the array contains N=4N = 4 integers and M=45M = 45. The largest possible value of kk that gives a good universe is 1414 ($(30 \text{ xor } 14) + (0 \text{ xor } 14) + (4 \text{ xor } 14) + (11 \text{ xor } 14) = 45$).

In sample case #3, the array contains N=1N = 1 integer and M=0M = 0. The largest possible value of kk that gives a good universe is 100100 (100 xor 100=0100 \text{ xor } 100 = 0).

In sample case #4, there is no value of kk that gives a good universe, so the answer is −1-1.

Limits

1≤T≤1001 \le T \le 100.

1≤N≤10001 \le N \le 1000.

Test set 1 (Visible)

0≤M≤1000 \le M \le 100.

0≤Ai≤1000 \le A_i \le 100, for all ii.

Test set 2 (Hidden)

0≤M≤10150 \le M \le 10^{15}.

0≤Ai≤10150 \le A_i \le 10^{15}, for all ii.