CF1360H.Binary Median

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider all binary strings of length mm ( 1m601 \le m \le 60 ). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly 2m2^m such strings in total.

The string ss is lexicographically smaller than the string tt (both have the same length mm ) if in the first position ii from the left in which they differ, we have s[i]<t[i]s[i] < t[i] . This is exactly the way strings are compared in dictionaries and in most modern programming languages when comparing them in a standard way. For example, the string 01011 is lexicographically smaller than the string 01100, because the first two characters are the same, and the third character in the first string is less than that in the second.

We remove from this set nn ( 1nmin(2m1,100)1 \le n \le \min(2^m-1, 100) ) distinct binary strings a1,a2,,ana_1, a_2, \ldots, a_n , each of length mm . Thus, the set will have k=2mnk=2^m-n strings. Sort all strings of the resulting set in lexicographical ascending order (as in the dictionary).

We number all the strings after sorting from 00 to k1k-1 . Print the string whose index is k12\lfloor \frac{k-1}{2} \rfloor (such an element is called median), where x\lfloor x \rfloor is the rounding of the number down to the nearest integer.

For example, if n=3n=3 , m=3m=3 and a=[a=[ 010, 111, 001 ]] , then after removing the strings aia_i and sorting, the result will take the form: [[ 000, 011, 100, 101, 110 ]] . Thus, the desired median is 100.

输入格式

The first line contains an integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases. Then, tt test cases follow.

The first line of each test case contains integers nn ( 1nmin(2m1,100)1 \le n \le \min(2^m-1, 100) ) and mm ( 1m601 \le m \le 60 ), where nn is the number of strings to remove, and mm is the length of binary strings. The next nn lines contain a1,a2,,ana_1, a_2, \ldots, a_n — distinct binary strings of length mm .

The total length of all given binary strings in all test cases in one test does not exceed 10510^5 .

输出格式

Print tt answers to the test cases. For each test case, print a string of length mm — the median of the sorted sequence of remaining strings in the corresponding test case.

输入输出样例

  • 输入#1

    5
    3 3
    010
    001
    111
    4 3
    000
    111
    100
    011
    1 1
    1
    1 1
    0
    3 2
    00
    01
    10

    输出#1

    100
    010
    0
    1
    11

说明/提示

The first test case is explained in the statement.

In the second test case, the result after removing strings and sorting is [[ 001, 010, 101, 110 ]] . Therefore, the desired median is 010.

首页