ABC422D.D - Least Unbalanced

Type: Default Time 2000 ms Memory 256 MiB 6 尝试 1 已通过 1 Tags

D - Least Unbalanced

Score : 400400 points

Problem Statement

Let NN be a positive integer. Define the imbalance of a sequence A=(A_1,A_2,,A_2N)A=(A\_1, A\_2, \dots, A\_{2^N}) of non-negative integers of length 2N2^N as the non-negative integer value obtained by the following operation:

  • Initially, set X=0X=0.
  • Perform the following series of operations NN times:
    • Update XX to max(X,max(A)min(A))\max(X, \max(A) - \min(A)), where max(A)\max(A) and min(A)\min(A) denote the maximum and minimum values of sequence AA, respectively.
    • Form a new sequence of half the length by pairing elements from the beginning two by two and arranging their sums. That is, set $A \gets (A\_1 + A\_2, A\_3 + A\_4, \dots, A\_{\vert A \vert - 1} + A\_{\vert A \vert})$.
  • The final value of XX is the imbalance.

For example, when N=2,A=(6,8,3,5)N=2, A=(6, 8, 3, 5), the imbalance is 66 through the following steps:

  • Initially, X=0X=0.
  • The first series of operations is as follows:
    • Update XX to max(X,max(A)min(A))=max(0,83)=5\max(X, \max(A) - \min(A)) = \max(0, 8 - 3) = 5.
    • Set AA to (6+8,3+5)=(14,8)(6+8, 3+5) = (14, 8).
  • The second series of operations is as follows:
    • Update XX to max(X,max(A)min(A))=max(5,148)=6\max(X, \max(A) - \min(A)) = \max(5, 14 - 8) = 6.
    • Set AA to (14+8)=(22)(14 + 8) = (22).
  • Finally, X=6X=6.

You are given a non-negative integer KK. Among all sequences of non-negative integers of length 2N2^N with sum KK, construct a sequence that minimizes the imbalance.

Constraints

  • 1N201 \leq N \leq 20
  • 0K1090 \leq K \leq 10^9
  • NN and KK are integers.

Input

The input is given from Standard Input in the following format:

$N$ $K$

Output

Let B=(B_1,B_2,,B_2N)B=(B\_1,B\_2,\dots,B\_{2^N}) be a sequence with minimum imbalance. Let UU be the imbalance of BB. Output a solution in the following format:

$U$
$B_1$ $B_2$ $\dots$ $B_{2^N}$

If there are multiple solutions, any of them will be considered correct.


(5,6)(5, 6) is a sequence with imbalance 11, which is the minimum imbalance among sequences satisfying the condition.


Samples

1 11
1
5 6
3 56
0
7 7 7 7 7 7 7 7

在线编程 IDE

建议全屏模式获得最佳体验