Editorial for COCI '11 Contest 1 #2 Matrix
Submitting an official solution before solving the problem yourself is a bannable offence.
A solution that iterates over all possible squares (by selecting all combinations of an upper-left cell and side length) and computes sums of diagonals for each of them has complexity
A faster solution, with complexity
The algorithm described above must cover two cases: when the square centre is a matrix cell (i.e. with an odd-length square side) and when it is a corner of four cells (with an even-length side). The latter case is marginally more involved to implement.
Comments