Given a matrix made of digits 1, 2, …, 9, we must count how many submatrices (consecutive subrow of size 9), and how many submatrices (consecutive subcolumn of size 9) contain all digits 1, 2, …, 9.
For instance, pay attention to this matrix:
1234567891
2345678912
3456789123
4567891234
5678912345
6789123456
7891234567
8912345678
9123456789
At each row there are two subrows of size 9 with all digits, and at every column there is one subcolumn of size 9 with all digits (the column itself is the subcolumn). Therefore, in this case the answer would be 18 10.
The input has several cases. Each case starts with two numbers in the first line, followed by a matrix of size made of digits 1, 2, …, 9 (i.e. lines with digits each).
For each case, the program must write in a new line the number of subrows and number of subcolumns of size 9 where all digits 1, 2, …, 9 appear.
There is no need to optimize, since any reasonable implementation will pass the private tests.
Evaluation over 10 points:
Slow solution: 5 points.
Fast solution: 10 points.
We define a fast solution as one which is correct, has linear cost and passes both public and private test cases. We define as a slow solution one which is not fast, but it is correct and passes the public test cases.
Author: PRO1
Generation: 2026-01-25T23:05:51.554Z
© Jutge.org, 2006–2026.
https://jutge.org