#P1647. Lexicographically Minimal Bit Flip Sequence

    ID: 14933 Type: Default 1000ms 256MiB

Lexicographically Minimal Bit Flip Sequence

Lexicographically Minimal Bit Flip Sequence

You are given two integers \(N\) and \(K\). Consider all the integers from \(0\) to \(2^N - 1\) (each represented as an \(N\)-bit binary string with possible leading zeros). We want to form a permutation (a sequence containing each number exactly once) of these \(2^N\) numbers with the following properties:

  1. The sequence starts with \(0\) (i.e. "000...0").
  2. For every two consecutive numbers in the sequence, say \(X\) and \(Y\), the number \(Y\) is obtained from \(X\) by flipping one or more bits that all have the same initial value in \(X\). In other words, you choose a non-empty set of positions in the binary representation of \(X\) which are either all \(0\)'s (and flip them to \(1\)'s) or are all \(1\)'s (and flip them to \(0\)'s), but you cannot mix the two choices in one move.
  3. If there are several options for the next number (i.e. several valid moves that produce numbers that have not yet appeared), you must choose the one with the smallest numerical value.

Your task is: Given \(N\) and \(K\), determine the maximum value among the first \(K\) numbers in the resulting sequence, and output that maximum in binary using exactly \(N\) digits (pad with leading zeros if necessary).

Note on LaTeX formulas: All formulas in the statement above are in LaTeX format.

inputFormat

The input consists of a single line containing two integers \(N\) and \(K\) separated by a space.

\(N\) represents the number of bits, and \(K\) indicates that you must consider the first \(K\) terms of the sequence.

outputFormat

Output a single line containing the binary representation (with exactly \(N\) bits) of the maximum number among the first \(K\) terms of the sequence.

sample

2 3
11