luogu#P7949. [✗✓OI R1] 左方之地

[✗✓OI R1] 左方之地

Background

In the epilogue, it will be described in detail why the “Land of Saki” can become the leader of the “Six Handsome Guys of Toaru Majutsu no Index”.

If you are wondering why the title does not include “Vento of the Front”, then you may want to check div.2.

But before that, you need to solve a construction problem.

Problem Description

You are given a natural number nn and a natural number parameter kk. You need to construct a sequence aa of length 2n2^n such that every integer in [0,2n)[0, 2^n) appears exactly once, and for all i[2,2n]i \in [2, 2^n], popcount(aiai1)=k\operatorname{popcount}(a_i \oplus a_{i-1}) = k.
Here, popcount(x)\operatorname{popcount}(x) denotes the number of 11 bits in the binary representation of xx, and \oplus denotes the bitwise XOR operation.

If a solution exists, output 1 and print the sequence; otherwise, output 0.

Input Format

One line with two integers n,kn, k, with the same meaning as in the statement.

Output Format

Output one integer 0 or 1 on the first line, where 0 means that no such sequence exists, and 1 means that such a sequence exists.
If the first line is 1, output 2n2^n integers on the next line, representing the sequence you construct. If there are multiple valid sequences, output any one.

4 3
1
0 14 3 13 6 8 5 11 12 2 15 1 10 4 9 7
4 2
0

Hint

This problem uses Special Judge and subtask-based evaluation.

For 100%100\% of the testdata, it is guaranteed that 1n,k201 \le n, k \le 20.

Subtask ID nn kk Points Dependencies
0 4\le 4 5
1 8\le 8 25 Subtask 0
2 =1=1 10
3 =n1=n-1 15
4 45 Subtask 0~3

Translated by ChatGPT 5