CF1360H Binary Median
Description
Consider all binary strings of length $ m $ ( $ 1 \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 $ 2^m $ such strings in total.
The string $ s $ is lexicographically smaller than the string $ t $ (both have the same length $ m $ ) if in the first position $ i $ from the left in which they differ, we have $ 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 $ n $ ( $ 1 \le n \le \min(2^m-1, 100) $ ) distinct binary strings $ a_1, a_2, \ldots, a_n $ , each of length $ m $ . Thus, the set will have $ k=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 $ 0 $ to $ k-1 $ . Print the string whose index is $ \lfloor \frac{k-1}{2} \rfloor $ (such an element is called median), where $ \lfloor x \rfloor $ is the rounding of the number down to the nearest integer.
For example, if $ n=3 $ , $ m=3 $ and $ a=[ $ 010, 111, 001 $ ] $ , then after removing the strings $ a_i $ and sorting, the result will take the form: $ [ $ 000, 011, 100, 101, 110 $ ] $ . Thus, the desired median is 100.
Input Format
N/A
Output Format
N/A
Explanation/Hint
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.