Given a matrix of digits, we have to produce a new matrix of digits with the same dimensions, where the digit in each position is calculated in the following way.
Let be a position in , and let be the digit in . Then, is the number of occurrences of in within row , plus the number of occurrences of in within column , and all of it modulus so that the result is again a digit.
Note that the occurrence of at position will be counted twice, one for row and another for column .
For instance, consider this matrix :
0044
5233
2221
1150
Then, the resulting matrix is:
3333
2333
4542
3322
For instance, . At row we have only one . And at column we have two . Therefore .
The input has several cases. Each case starts with two positive natural numbers, , in one line. After that comes a matrix of digits ( lines with digits each), followed by an empty line.
For each case, the program has to write lines with digits each, which is the resulting matrix, followed by an empty line.
Evaluation out of 10 points:
Slow solution: 5 points.
Fast solution: 10 points.
A fast solution is one which is correct, of linear cost and passing the test cases, both public and private. A slow solution is one which is not fast, but it is correct and passes the public test cases.
Author: PRO1
Generation: 2026-01-25T22:38:39.288Z
© Jutge.org, 2006–2026.
https://jutge.org