#P15093. [UOI 2025 II Stage] Odd Rows
[UOI 2025 II Stage] Odd Rows
题目描述
Once, s1mple approached Kostya, a well-known problem solver, and said:
$\textit{If you want to become better, you need constant practice. Here is a problem for training:}$
Given a matrix of size ( --- number of rows; --- number of columns), where each element is either or . It is known that each column contains exactly ones. The elements within each column can be arranged freely. The goal is to maximize the number of rows with an odd number of ones and to find such a matrix.
Kostya silently nodded, sat down at the table, and began to work, knowing that every practice brings him closer to mastery.
Kostya couldn't solve the problem and is asking you to help him solve it.
$\textbf{You can earn partial points if you only find the number, not the matrix. More details below.}$
输入格式
The first line contains two integers and --- the dimensions of the matrix.
The second line contains integers --- the number of ones in each column.
输出格式
In the first line, output a single integer () --- the number of rows in the matrix with an odd sum.
In each of the next lines, output integers () --- the numbers of the matrix.
8 4
6 1 6 1
6
1 1 1 0
1 0 1 1
1 0 1 0
1 0 1 0
1 0 0 0
1 0 0 0
0 0 1 0
0 0 1 0
4 4
3 0 3 0
2
1 0 1 0
1 0 1 0
1 0 0 0
0 0 1 0
7 3
4 3 2
7
1 1 1
1 0 0
1 0 0
1 0 0
0 1 0
0 1 0
0 0 1
提示
In the first example, the first and third columns intersect in at least positions, meaning that if there were only these two columns, we would have even rows, but since there are also two columns with one, we can convert two of them to odd, so the optimal answer will be odd rows.
In the second example, we can ignore the second and fourth columns because they have no ones, meaning they will not change the parity of any row, and the first and third intersect in at least rows, meaning at least two rows will be even, so the answer is .
In the third example, the answer is , because there exists a matrix that has odd rows and satisfies the condition, and there is no matrix that has more than .
Scoring
- ( points): ;
- ( points): the number of ones in the matrix does not exceed ;
- ( points): the number of ones in each column does not exceed ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): no additional restrictions.
You can earn half the points for each block if you output the correct for each test in the block.
Note that to earn partial points, you need to output the correct and
- either output nothing more; that is, output only , but not the matrix;
- or output the complete matrix consisting of s and s, which does not have to be correct. For example, one that consists entirely of zeros.
If you output, for example, only a few rows, or too many rows, numbers other than and , etc., you will receive points.