题目链接

Consider all binary strings of length m (1≤m≤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 2m 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 ≤ n ≤ m i n ( 2 m − 1 , 100 ) ) n (1≤n≤min(2^{m−1},100)) n(1≤n≤min(2m−1,100)) distinct binary strings a1,a2,…,an, each of length m. Thus, the set will have k=2m−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 ⌊k−1⌋/2 (such an element is called median), where ⌊x⌋ 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 ai and sorting, the result will take the form: [000, 011, 100, 101, 110]. Thus, the desired median is 100.

Input

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

The first line of each test case contains integers n ( 1 ≤ n ≤ m i n ( 2 m − 1 , 100 ) ) n (1≤n≤min(2^{m−1},100)) n(1≤n≤min(2m−1,100)) and m (1≤m≤60), where n is the number of strings to remove, and m is the length of binary strings. The next n lines contain a1,a2,…,an — distinct binary strings of length m.

The total length of all given binary strings in all test cases in one test does not exceed 1 0 5 10^5 105.

Output

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.

Example

input

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

output

100
010
0
1
11

这题用到了位运算,我们把所有二进制字符串转化为十进制存入数组 a a a,考虑到内存限制, b i t s e t bitset bitset 恰好完美地解决了这个问题,我们先定位要找的那个数的位置 p o s pos pos,也即十进制里面的大小,然后遍历数组 a a a,如果有数小于等于 p o s pos pos,则 p o s + 1 pos+1 pos+1,最后再将其转化为二进制输出即可,AC代码如下:

#include <bits/stdc++.h>typedef long long ll;
using namespace std;void solve() {int n, m;cin >> n >> m;ll a[n];string s;ll ans = ((1LL << m) - n - 1) / 2;for (int i = 0; i < n; i++) {cin >> s;a[i] = bitset<64>(s).to_ullong();}sort(a, a + n);for (auto i:a) ans += (i <= ans);cout << bitset<64>(ans).to_string().substr(64 - m) << endl;
}int main() {int t;cin >> t;while (t--) solve();
}

Codeforces Round #644 (Div. 3) H.Binary Median相关推荐

  1. Codeforces Round #644 (Div. 3) E.Polygon

    Codeforces Round #644 (Div. 3) E.Polygon 题目链接 Polygon is not only the best platform for developing p ...

  2. Codeforces Round #644 (Div. 3) D.Buying Shovels

    Codeforces Round #644 (Div. 3) D.Buying Shovels 题目链接 Polycarp wants to buy exactly n shovels. The sh ...

  3. Codeforces Round #644 (Div. 3) G.A/B Matrix

    Codeforces Round #644 (Div. 3) G.A/B Matrix 题目链接 You are given four positive integers n, m, a, b (1≤ ...

  4. Codeforces Round #644 (Div. 3) F.Spy-string

    Codeforces Round #644 (Div. 3) F.Spy-string 题目链接 You are given n strings a1,a2,-,an: all of them hav ...

  5. Codeforces Round #644(Div. 3) A-H

    A - Minimal Square 题意 给两个完全一样的矩形(平行且不重叠) 求能覆盖两个矩形的最小正方形的面积 思路 只有两种摆放方式 将两个矩形上下并列或者左右并列 得到的新图形 长或者宽是之 ...

  6. Codeforces Round #644 (Div. 3)(A-E)

    这场的A-E都是水题,就简单记录一下吧. Minimal Square CodeForces - 1360A 思路:我们令b=max(a,b),a=min(a,b). 如果b>=2*a的话,最终 ...

  7. Codeforces Round #703 (Div. 2) D. Max Median

    题意:给一个长度为n的序列,对于一个区间长度不小于k的子区间,中位数为这个区间排序后的第(k+1)/2个数字.现在求所有的长度不小于k的子区间,中位数的最大值是多少. 思路:首先要想到,对于一个中位数 ...

  8. Codeforces Round #715 (Div. 2) D. Binary Literature 构造

    传送门 文章目录 题意: 思路: 题意: 给你个nnn和三个长度为n∗2n*2n∗2的串,让你构造一个长度≤n∗3\le n*3≤n∗3的串,使其子序列包含至少两个给定串. 思路: 先考虑如果没有长度 ...

  9. Codeforces Round #703 (Div. 2) D . Max Median 二分 +思维

    传送门 题意: 给定一个数组和k,求一段连续区间中位数最大值,连续区间长度>=k. 如果=k的话可以直接秒了,这里是>=k,我们可以通过二分让后利用>=k这个条件来检查答案. 二分中 ...

最新文章

  1. (摘要)100个伟大的商业理念:理念34:企业社会责任
  2. 为什么Android项目mainactivity中有一个变量R_博客笔记大汇总,Android优化总结篇
  3. Nginx服务器的Web请求处理机制
  4. mysql查询有数据但返回null_Mybatis查不到数据查询返回Null问题
  5. Pair Project:电梯控制程序 编写心得 最新版
  6. MySQL索引原理及慢查询优化
  7. 数据结构与算法之-----二叉树(二)
  8. Hyperledger Fabric教程(12)-- 交易过程
  9. 滞后问题_富锂正极材料的电压滞后问题
  10. 事业心是成功的“动力源”
  11. Ios 12 linux,iOS12.3~12.4.2支持越狱?包括 A12 设备
  12. 1.camera硬件接口学习-DVP,MIPI-CSI2,USB
  13. Biotin-WFA,WFL;生物素化紫藤凝集素(WFA,WFL)
  14. ITASCA PFC 2D3D DISCERETE ELEMENT MODELING
  15. cass块参照怎么改颜色_【干货】CASS自定义图斑填充技巧
  16. Android 设计模式之MVC,从一个实例中来理解MVC
  17. Git - 团队合作利器 Branch 与 Git Flow
  18. NOIP备战题解集(11.10)
  19. 计算机技术在家庭方面的应用,物联网技术在家庭方面的应用
  20. Anaconda创建虚拟环境、配环境变量步骤笔记

热门文章

  1. linux系统配置sftp服务器,linux配置sftp服务器配置
  2. Java中append方法和add方法的区别
  3. TTL与OC电路和MOS管
  4. 博客园自定义背景图片
  5. 数据仓库——数据仓库基础
  6. mysql point 经纬度_lbs - Mysql POINT类型数据,怎么计算经纬度偏差
  7. TMS320F28335中断向量表
  8. 远程服务器返回错误: (500) 内部服务器错误解决办法
  9. 台式机装苹果系统_iOS系统如何安装外来App?教你一键设置!苹果手机怎么装第三方软件?...
  10. 动态代理及JDK动态代理源码分析