#P5953. [POI 2018] Różnorodność

[POI 2018] Różnorodność

Problem Description

Given a matrix with nn rows and mm columns, for every consecutive sub-square with both side lengths equal to kk, count the number of distinct values that appear inside it.

Input Format

The first line contains three positive integers n,m,kn, m, k. The next nn lines each contain mm positive integers a[i][j](1<=a[i][j]<=100000)a[i][j] (1<=a[i][j]<=100000), representing the value at each position in the matrix.

Output Format

Output one line with two integers MM and SS. Let f(i,j)f(i,j) denote the number of distinct values that appear in the square whose top-left corner is (i,j)(i,j). Then MM is the maximum value of ff, and SS is the sum of all values of ff.

3 5 2
1 5 3 3 3
4 1 3 3 4
4 2 4 4 3
4 20

Hint

For 100%100\% of the testdata, n,m3000n, m \le 3000, and kmin(n,m)k \le \min(n, m).

Translated by ChatGPT 5