Count submatrices 3x3 with all digits 1, 2, ...,9

Given a matrix with digits 1, 2, …, 9, you must count how many
submatrices of size 3 × 3 of the given matrix contain all different
digits 1, 2, …, 9.

Input

The input has several cases. Each one starts with two positive natural
numbers n, m in the first line. Afterwards comes a matrix of size n × m
with digits 1, 2, …, 9 (n lines with m digits each).

Output

For each case, the program must write in a new line the number of
submatrices 3 × 3 inside of which all digits 1, 2, …, 9 appear.

Observation

There is no need to optimize this problem. Any reasonably efficient
implementation will pass.

Evaluation over 10 points:

- Passes public test cases: 5 points.

- Passes public and private test cases: 10 points.

Problem information

Author: PRO1

Generation: 2026-01-25T21:58:13.204Z

© Jutge.org, 2006–2026.
https://jutge.org
