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

33766번 - Sequence Construction 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB114494344.792%

문제

Lately, the cows on Farmer John's farm have been infatuated with watching the show Apothecowry Dairies. The show revolves around a clever bovine sleuth CowCow solving problems of various kinds. Bessie found a new problem from the show, but the solution won't be revealed until the next episode in a week! Please solve the problem for her.

You are given integers $M$ and $K$ $(1 \leq M \leq 10 ^ 9, 1 \leq K \leq 31)$. Please choose a positive integer $N$ and construct a sequence $a$ of $N$ non-negative integers such that the following conditions are satisfied:

  • 1ドル \le N \le 100$
  • $a_1 + a_2 + \dots + a_N = M$
  • $\text{popcount}(a_1) \oplus \text{ popcount}(a_2) \oplus \dots \oplus \text{ popcount}(a_N) = K$

If no such sequence exists, print $-1$.

$\dagger \text{ popcount}(x)$ is the number of bits equal to 1ドル$ in the binary representation of the integer $x$. For instance, the popcount of 11ドル$ is 3ドル$ and the popcount of 16ドル$ is 1ドル$.

$\dagger \oplus$ is the bitwise xor operator.

The input will consist of $T$ (1ドル \le T \le 5 \cdot 10^3$) independent test cases.

입력

The first line contains $T$.

The first and only line of each test case has $M$ and $K$.

It is guaranteed that all test cases are unique.

출력

Output the solutions for $T$ test cases as follows:

If no answer exists, the only line for that test case should be $-1$.

Otherwise, the first line for that test case should be a single integer $N,ドル the length of the sequence -- (1ドル \le N \le 100$).

The second line for that test case should contain $N$ space-separated integers that satisfy the conditions -- (0ドル \le a_i \le M$).

제한

예제 입력 1

3
2 1
33 5
10 5

예제 출력 1

2
2 0
3
3 23 7
-1

In the first test case, the elements in the array $a = [2, 0]$ sum to 2ドル$. The xor sum of popcounts is 1ドル \oplus 0 = 1$. Thus, all the conditions are satisfied.

In the second test case, the elements in the array $a = [3, 23, 7]$ sum to 33ドル$. The xor sum of the popcounts is 2ドル \oplus 4 \oplus 3 = 5$. Thus, all conditions are satisfied.

Other valid arrays are $a = [4, 2, 15, 5, 7]$ and $a = [1, 4, 0, 27, 1]$.

It can be shown that no valid arrays exist for the third test case.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Silver 1번

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

출처

대학교 대회

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

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