Codeforces Round 1048 (Div. 2)
C
Cake Assignment
Codeforces
未评级
原题
← BD →
翻译中…

Chocola and Vanilla love cakes. Today, the manager of a cake shop gave them a total of $2^{k+1}$ cakes. The cakes were distributed evenly, so each of them initially received $2^k$ cakes.

翻译中…

However, Chocola and Vanilla now want to redistribute the cakes such that Chocola ends up with exactly $x$ cakes and Vanilla gets the remaining $2^{k+1}-x$ cakes.

翻译中…

In one step, they can perform exactly one of the following two operations:

翻译中…
  1. Chocola gives half of her cakes to Vanilla. This operation is only allowed if Chocola currently has an even number of cakes.
  2. Vanilla gives half of her cakes to Chocola. This operation is only allowed if Vanilla currently has an even number of cakes.
翻译中…

Your task is to determine the minimum number of steps required to reach the target distribution and to output any valid sequence of operations achieving that minimum.

翻译中…

It can be proven that, under the given constraints, a valid solution always exists, and the minimum number of steps required is at most $120$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $k$ and $x$ ($1 \le k \le 60$, $1 \le x \le 2^{k+1}-1$) — each person initially received $2^k$ cakes, and $x$ is the number of cakes Chocola should have after redistribution.

翻译中…

Output

翻译中…

For each test case, output a single integer $n$ ($0\le n\le 120$) representing the minimum number of steps required for them to redistribute the cakes accordingly.

翻译中…

On the next line, output $n$ integers $o_1, o_2, \ldots, o_n$ ($o_i = \mathtt{1}$ or $o_i = \mathtt{2}$), where $o_i = \mathtt{1}$ means that in the $i$-th step, Chocola gave half of her cakes to Vanilla (operation 1), and $o_i = \mathtt{2}$ means that Vanilla gave half of her cakes to Chocola (operation 2).

翻译中…

Note

翻译中…

In the first test case, they can use the following steps so that Chocola has exactly $x = 3$ cakes and Vanilla has exactly $2 ^ {k + 1} - x = 5$ cakes. We use $\{a, b\}$ to denote that Chocola currently has $a$ cakes and Vanilla currently has $b$ cakes.

翻译中…

$$\{4, 4\} \xrightarrow{o_1 = \mathtt{2}} \{6, 2\} \xrightarrow{o_2 = \mathtt{1}} \{3, 5\}$$

翻译中…

In the second test case, Chocola already has exactly $x = 4$ cakes and Vanilla already has exactly $2 ^ {k + 1} - x = 4$ cakes, so no operations are required.

翻译中…

In the third test case, they can use the following steps so that Chocola has exactly $x = 7$ cakes and Vanilla has exactly $2 ^ {k + 1} - x = 9$ cakes.

翻译中…

$$\{8, 8\} \xrightarrow{o_1 = \mathtt{2}} \{12, 4\} \xrightarrow{o_2 = \mathtt{2}} \{14, 2\} \xrightarrow{o_3 = \mathtt{1}} \{7, 9\}$$

翻译中…

样例

Input #1
4
2 3
2 4
3 7
2 5
Output #1
2
2 1
0

3
2 2 1
2
1 2
InputCopy OutputCopy
题目信息
题号
2139C
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。