Each case of the input in this exercise is a matrix of 0s and 1s. The program has to compute the total number of non-empty submatrices that are square and constant (same number of rows and columns and the same symbol). For instance, consider this as the input matrix:
00001
00011
00011
01111
It has 1 constant submatrix of size (with 0s), 6 constant submatrices (4 of them with 0s, and 2 of them with 1s), and 20 constant submatrices . Therefore, in this case the output would be .
The input has several cases. Each case starts with a line with two positive naturals and . After that come lines with characters, either or , which describe a matrix of size , followed by an empty line.
For each case, the program must write the total number of non-empty square submatrices in one 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-25T14:26:08.642Z
© Jutge.org, 2006–2026.
https://jutge.org