Codechef September long challenge 2021 | XOR Equal Solution
You are given an array AA consisting of NN integers and an integer XX. Your goal is to have as many equal integers as possible in the array. To achieve this goal, you can do the following operation:
- Choose an index ii (1≤i≤N)(1≤i≤N) and set Ai=Ai⊕XAi=Ai⊕X, where ⊕⊕ denotes the bitwise xor operation.
Find the maximum number of equal integers you can have in the final array and the minimum number of operations to obtain these many equal integers.
Input Format
- The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
- Each test case contains two lines of input.
- The first line of each test case contains two space-separated integers N,XN,X.
- The second line of each test case contains NN space-separated integers A1,A2,…,ANA1,A2,…,AN.
Output Format
For each test case, print a single line containing two space-separated integers – first, the maximum number of equal integers in the final array and second, the minimum number of operations to achieve these many equal integers.
Constraints
- 1≤T≤1041≤T≤104
- 1≤N≤1051≤N≤105
- 0≤X≤1090≤X≤109
- 0≤Ai≤1090≤Ai≤109
- The sum of NN over all test cases does not exceed 5⋅1055⋅105.
Subtasks
Subtask #1 (100 points): Original constraints
Sample Input 1
3
3 2
1 2 3
5 100
1 2 3 4 5
4 1
2 2 6 6
Sample Output 1
2 1
1 0
2 0
C++ Solution
Tags:
Solutions