A13538 | Binary Median
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains an integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Then, $t$ test cases follow.
The first line of each test case contains integers $n$ ( $1 \le n \le \min(2^m-1, 100)$ ) and $m$ ( $1 \le m \le 60$ ), where $n$ is the number of strings to remove, and $m$ is the length of binary strings. The next $n$ lines contain $a_1, a_2, \ldots, a_n$ — distinct binary strings of length $m$ .
The total length of all given binary strings in all test cases in one test does not exceed $10^5$ .
The first line of each test case contains integers $n$ ( $1 \le n \le \min(2^m-1, 100)$ ) and $m$ ( $1 \le m \le 60$ ), where $n$ is the number of strings to remove, and $m$ is the length of binary strings. The next $n$ lines contain $a_1, a_2, \ldots, a_n$ — distinct binary strings of length $m$ .
The total length of all given binary strings in all test cases in one test does not exceed $10^5$ .
输出格式
Print $t$ answers to the test cases. For each test case, print a string of length $m$ — 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.
In the second test case, the result after removing strings and sorting is $[$ 001, 010, 101, 110 $]$ . Therefore, the desired median is 010.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted