#K69762. Minimum Moves to Zero Each Row
Minimum Moves to Zero Each Row
Minimum Moves to Zero Each Row
You are given one or more matrices. For each matrix, process each row separately and determine the minimum number of moves needed to turn every number in the row into 0. In a single move, you can select any positive integer from the row, and change every occurrence of that integer to 0.
Note: Zero values are already 0 and do not require any move.
For example, for the row [1, 2, 2], you need 2 moves to cover numbers 1 and 2. For the row [3, 3, 3], only 1 move is needed, and so on.
The input consists of multiple test cases. Each test case begins with two integers representing the number of rows and the number of columns of the matrix, followed by the matrix rows. For each test case, output a single line containing the answer for each row (the number of moves), separated by a space.
All formulas in this problem are written in \(\LaTeX\) format if needed. For example, if we wish to denote the set of positive integers in a row \(R\), we would write \(\{ x \in R \mid x>0 \}\).
inputFormat
The first line contains an integer \(T\) denoting the number of test cases.
For each test case:
- The first line contains two integers \(r\) and \(c\) representing the number of rows and columns respectively.
- This is followed by \(r\) lines, each containing \(c\) space-separated non-negative integers which form the matrix.
All input is provided through standard input (stdin).
outputFormat
For each test case, output a single line containing \(r\) space-separated integers, where each integer is the minimum number of moves required for that row.
All output should be written to standard output (stdout).
## sample1
1 3
1 2 2
2
</p>