아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

AND MEX

시간 제한2초메모리 제한1024 MB

요약
모든 원소에 비트 AND를 적용할 값 x를 골라 결과 배열의 MEX가 최대가 되도록 한다.
난이도

보통10점 중 6점

유형
비트 연산, 그리디, 해시맵
정답자
아직 제출이 없습니다

문제

We define the beauty of an array as the value of its minimum excluded value (MEX†^{\dagger}). A larger MEX corresponds to a more beautiful array.

You are given an array AA of length NN. You want to enhance it in terms of its beauty. To achieve this, you can choose a non-negative integer xx and replace each element A_iA\_i with A_i∧xA\_i\wedge x where ∧\wedge denotes the bitwise AND operator.

Find the optimal value of xx that maximizes the beauty of the array.

입력

The first line contains a single integer TT --- the number of test cases.

The first line of each test case contains a single integer NN.

The second line of each test case contains NN space-separated integers A_1,…,A_NA\_1,\ldots ,A\_N.

출력

For each test case, print a single line containing a single integer xx that maximizes the MEX of the array formed by taking the bitwise AND of each element of AA with xx. If there are multiple solutions, you may print any.

제한

  • 1≤T≤100,0001\le T\le 100\\, 000
  • 1≤N≤100,0001\le N\le 100\\, 000
  • 0≤A_i<230 (1≤i≤N)0\le A\_i<2^{30}\ (1\le i\le N)
  • It is guaranteed that the sum of NN over all test cases does not exceed 100,000100\\, 000.
  • All values in the input are integers.
  • 0≤x<2300\le x<2^{30}
  • It can be shown that there always exists an optimal xx in the specified range.

힌트

In the sample, we can choose x=23x=23, so the new array will be \[[13\wedge 23,\, 11\wedge 23,\, 40\wedge 23,10\wedge 23,\, 33\wedge 23,\, 19\wedge 23] =[5,3,0,2,1,19]\] which has a MEX of 44. Another possible answer is x=19x=19.

†{}^{\dagger} The MEX of an array is the smallest non-negative integer that does not belong to the array. For instance, the MEX of \[2,2,1]\[2,2,1] is 00, the MEX of \[3,1,0,1]\[3,1,0,1] is 22, and the MEX of \[0,3,1,2]\[0,3,1,2] is 44.

예제1

  1. 예제 1

    입력
    1
    6
    13 11 40 10 33 19
    
    예상 출력
    23