Logo
(追記) (追記ここまで)

23116번 - AND 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB139776357.798%

문제

You had an array $a$. After that, you calculated bitwise ANDs of all subarrays of the original array. Formally, you calculated all numbers of the form $a_i$ AND $a_{i + 1}$ AND $\ldots$ AND $a_j$ for 1ドル \le i \le j \le \mathrm{length}(a)$.

You remember the resulting set of all these numbers: a number lies in this set if and only if it can be represented as bitwise AND of at least one subarray. Sadly, you forgot the original array.

Find any array $a$ which would produce the given set of ANDs on subarrays, or determine that there is no such array.

입력

The first line contains a single integer $t$ (1ドル \le t \le 10^5$), the number of test cases.

The first line of each test case contains a single integer $n$ (1ドル \le n \le 10^5$), the size of the given set.

The second line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ (0ドル \le b_i \le 2^{20} - 1$), the elements of the set. It is guaranteed that all elements are distinct.

It is guaranteed that the sum of $n$ over all test cases does not exceed 10ドル^5$.

출력

For each test case, if there is no such array, output $-1$.

Otherwise, on the first line, output the size of the original array $k$ (1ドル \le k \le 5n$).

On the next line, output $k$ integers $a_1, a_2, \ldots, a_k$ (0ドル \le a_i \le 2^{20} - 1$), the elements of the array.

If there are several possible answers, print any one of them.

It can be shown that, if there is at least one array, then there is an array which satisfies these conditions.

제한

예제 입력 1

3
1
5
3
0 1 2
2
1 2

예제 출력 1

3
5 5 5
3
1 0 2
-1

힌트

Note that the elements of the array that you output don't have to be distinct.

출처

Camp > Petrozavodsk Programming Camp > Summer 2021 > Day 3: IQ test by kefaa2, antontrygubO_o, and gepardo A번

Contest > Open Cup > 2021/2022 Season > Stage 2: Grand Prix of IMO A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /