#abc346e. E - Paint
E - Paint
Score: points
问题陈述
有一个 行 列的网格。最初,所有单元格都涂有颜色 。
你将按照顺序 执行以下操作。
-
如果 ,则用颜色 重新涂画第 行的所有单元格。
-
如果 ,则用颜色 重新涂画第 列的所有单元格。
完成所有操作后,对于网格上存在的每种颜色 ,找出涂有颜色 的单元格数量。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a grid with rows and columns. Initially, all cells are painted with color .
You will perform the following operations in the order .
-
If , repaint all cells in the -th row with color .
-
If , repaint all cells in the -th column with color .
After all operations are completed, for each color that exists on the grid, find the number of cells that are painted with color .
Constraints
- for each such that ,
- for each such that .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the number of distinct integers such that there are cells painted with color . Print lines.
The first line should contain the value of .
The second and subsequent lines should contain, for each color that exists on the grid, the color number and the number of cells painted with that color.
Specifically, the -th line should contain the color number and the number of cells painted with color , in this order, separated by a space.
Here, print the color numbers in ascending order. That is, ensure that . Note also that is required.
Sample Input 1
3 4 4
1 2 5
2 4 0
1 3 3
1 3 2
Sample Output 1
3
0 5
2 4
5 3
The operations will change the colors of the cells in the grid as follows:
0000 0000 0000 0000 0000
0000 → 5555 → 5550 → 5550 → 5550
0000 0000 0000 3333 2222
Eventually, there are five cells painted with color , four with color , and three with color .
Sample Input 2
1 1 5
1 1 1
1 1 10
2 1 100
1 1 1000
2 1 10000
Sample Output 2
1
10000 1
Sample Input 3
5 5 10
1 1 1
1 2 2
1 3 3
1 4 4
1 5 5
2 1 6
2 2 7
2 3 8
2 4 9
2 5 10
Sample Output 3
5
6 5
7 5
8 5
9 5
10 5
update @ 2024/5/16 17:18:06