#arc176a. A - 01 Matrix Again
A - 01 Matrix Again
Score: points
问题陈述
有一个 的网格。用 表示从顶部数第 行,从左边数第 列的单元格。
你需要用 或 填充每个单元格。构建一种填充网格的方法,以满足以下所有条件:
- 单元格 包含 。
- 第 行的整数之和为 。
- 第 列的整数之和为 。
可以证明,在这个问题的约束条件下,至少有一种填充网格的方法可以满足这些条件。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is an grid. Let denote the cell at the -th row from the top and the -th column from the left.
You are to fill each cell with or . Construct one method to fill the grid that satisfies all of the following conditions:
- The cells contain .
- The integers in the -th row sum to .
- The integers in the -th column sum to .
It can be proved that under the constraints of this problem, there is at least one method to fill the grid that satisfies the conditions.
Constraints
- if .
Input
The input is given from Standard Input in the following format:
Output
Let be the cells that contain , and print the following:
If multiple methods satisfy the conditions, any of them will be considered correct.
Sample Input 1
4 2
1 4
3 2
Sample Output 1
8
1 2
1 4
2 1
2 4
3 2
3 3
4 1
4 3
This output fills the grid as follows. All the conditions are satisfied, so this output is correct.
0101
1001
0110
1010
Sample Input 2
3 3
3 1
2 3
1 3
Sample Output 2
9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Sample Input 3
7 3
1 7
7 6
6 1
Sample Output 3
21
1 6
2 4
4 1
7 3
3 6
4 5
6 1
1 7
7 6
3 5
2 2
6 3
6 7
5 4
5 2
2 5
5 3
1 4
7 1
4 7
3 2