| OCPC 2025 Summer, Day 8: Chromate Sent This to Dominater in His DMs and Dominater Said :---) Contest |
|---|
| Finished |
Hey, where did "Segment Tree Reconstruction 1" go?
A perfect binary tree is a binary tree in which all non-leaf nodes have two children, and all leaf nodes have the same depth.
There is a perfect binary tree with $$$2^n$$$ leaf nodes, where $$$0$$$ or $$$1$$$ is written on each node.
You will assign a value to each leaf node. Then, the values on non-leaf nodes change according to the following rule:
Here, the XOR value of two binary values is $$$1$$$ if the two values are different, and $$$0$$$ if they are equal.
Please assign values to the leaf nodes so that the sum of numbers on all nodes becomes exactly $$$k$$$, or determine that it is impossible. Also, if such an assignment exists, find the number of such assignments. Two assignments are different if there is a node with a different value in the two assignments. As the number of assignments may be huge, output it modulo $$$998\,244\,353$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 3000$$$). The description of the test cases follows.
The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 19$$$, $$$0 \le k \lt 2^{n+1}$$$).
It is guaranteed that the sum of $$$2^n$$$ over all test cases does not exceed $$$2^{19}$$$.
If it is possible to make the sum exactly $$$k$$$, output the number of assignments whose sum is $$$k$$$, modulo $$$998\,244\,353$$$.
Then, on the next line, output a binary string $$$S$$$ with length $$$2^n$$$. Formally, the perfect binary tree will be constructed as follows.
If it is impossible to make the sum exactly $$$k$$$, output $$$-1$$$ on a separate line.
71 01 22 13 53 64 194 22
1 00 3 01 -1 -1 60 00001101 6352 0001110101011101 -1
There is only one assignment with sum $$$0$$$ when $$$n=1$$$, shown in the example output.
There are three assignments with sum $$$2$$$ when $$$n=1$$$, which are $$$\mathtt{10}$$$, $$$\mathtt{01}$$$, and $$$\mathtt{11}$$$.
It can be shown that it is impossible to make the sum $$$5$$$ when $$$n=3$$$.
| Name |
|---|


