atcoder#AGC024F. [AGC024F] Simple Subsequence Problem

[AGC024F] Simple Subsequence Problem

Score : 23002300 points

Problem Statement

You are given a set SS of strings consisting of 0 and 1, and an integer KK.

Find the longest string that is a subsequence of KK or more different strings in SS. If there are multiple strings that satisfy this condition, find the lexicographically smallest such string.

Here, SS is given in the format below:

  • The data directly given to you is an integer NN, and N+1N+1 strings X0,X1,...,XNX_0,X_1,...,X_N. For every ii (0iN)(0\leq i\leq N), the length of XiX_i is 2i2^i.
  • For every pair of two integers (i,j)(i,j) (0iN,0j2i1)(0\leq i\leq N,0\leq j\leq 2^i-1), the jj-th character of XiX_i is 1 if and only if the binary representation of jj with ii digits (possibly with leading zeros) belongs to SS. Here, the first and last characters in XiX_i are called the 00-th and (2i1)(2^i-1)-th characters, respectively.
  • SS does not contain a string with length N+1N+1 or more.

Here, a string AA is a subsequence of another string BB when there exists a sequence of integers t1<...<tAt_1 < ... < t_{|A|} such that, for every ii (1iA)(1\leq i\leq |A|), the ii-th character of AA and the tit_i-th character of BB is equal.

Constraints

  • 0N200 \leq N \leq 20
  • Xi(0iN)X_i(0\leq i\leq N) is a string of length 2i2^i consisting of 0 and 1.
  • 1KS1 \leq K \leq |S|
  • KK is an integer.

Input

Input is given from Standard Input in the following format:

NN KK

X0X_0

::

XNX_N

Output

Print the lexicographically smallest string among the longest strings that are subsequences of KK or more different strings in SS.

3 4
1
01
1011
01001110
10

The following strings belong to SS: the empty string, 1, 00, 10, 11, 001, 100, 101 and 110. The lexicographically smallest string among the longest strings that are subsequences of four or more of them is 10.

4 6
1
01
1011
10111010
1101110011111101
100
2 5
0
11
1111

The answer is the empty string.