Codeforces Round 948 (Div. 2)
D
XORificator
Codeforces
2300
原题
← CE →
翻译中…

You are given a binary (consisting only of 0s and 1s) $n \times m$ matrix. You are also given a XORificator, using which you can invert all the values in a chosen row (i.e. replace 0 with 1 and 1 with 0).

翻译中…

A column in the matrix is considered special if it contains exactly one 1. Your task is to find the maximum number of columns that can be made special at the same time, and the set of rows the XORificator should be used on to achieve that.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n, m \leq 3 \cdot 10^5$, $n \cdot m \leq 3 \cdot 10^5$).

翻译中…

Each of the following $n$ lines of the test case contains a binary string of length $m$.

翻译中…

It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $3 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output two lines.

翻译中…

In the first line, output the maximum number of special columns that is possible to get simultaneously.

翻译中…

In the second line, output a binary string of length $n$, where the $i$-th character is 0, if you don't use the XORificator on the $i$-th row, and 1, if you use the XORificator on the $i$-th row.

翻译中…

If there are multiple valid XORificator configurations that achieve the optimal answer, you can output any of them.

翻译中…

Note

翻译中…

In the first test case, you can use the XORificator on the second row to make the columns $2$, $3$, and $4$ special.

翻译中…

In the second test case, the only column is already special, so you don't need to use the XORificator.

翻译中…

样例

Input #1
5
3 4
1010
0110
0100
1 1
1
1 1
0
2 5
00101
10110
3 3
101
111
000
Output #1
3
010
1
0
1
1
3
00
2
010
InputCopy OutputCopy
题目信息
题号
1977D
时间限制
2 s
内存限制
256 MB
标签
位运算
暴力
贪心
哈希

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。