목차

AND

ps
링크acmicpc.net/…
출처BOJ
문제 번호23116
문제명AND
레벨골드 1
분류

애드혹

시간복잡도O(∑n)
인풋사이즈∑n<=10^5
사용한 언어Python 3.11
제출기록43244KB / 324ms
최고기록324ms
해결날짜2023/08/22

풀이

코드

"""Solution code for "BOJ 23116. AND".

- Problem link: https://www.acmicpc.net/problem/23116
- Solution link: http://www.teferi.net/ps/problems/boj/23116

Tags: [ad hoc]
"""

import sys
import functools
import operator


def main():
    t = int(sys.stdin.readline())
    for _ in range(t):
        n = int(sys.stdin.readline())
        b = [int(x) for x in sys.stdin.readline().split()]

        andsum = functools.reduce(operator.and_, b)
        if andsum not in b:
            print('-1')
        else:
            answer = [andsum] * (n * 2)
            answer[::2] = b
            print(len(answer))
            print(*answer)


if __name__ == '__main__':
    main()