cswork / OAOpen practice workspace

MetaOA #15

Find All Local Maximums

Estimated MediumJudge-ready

Topics (AI-labelled)Simulation

For a non-zero cell (i,j) with value v, examine the square region of radius v centered on it, ignoring the center itself and the four corners of the original full square, and comparing only cells inside the matrix. If no other value is ≥v, the cell is a local maximum. Output the coordinates in ascending order of row, then column. The original site's example includes invalid points, so this site recomputed it.

Input

This site's input scale: R C (1..30), followed by R lines of C non-negative integers each (0..10⁹). Indices start from 0, and the four corners are defined by the full square; you must not exclude the corners of the clipped region instead.

Output

The first line is the number t of local maxima; the next t lines give row col (starting from 0), in ascending order of row, then column. If there are no maxima, output only 0.

Example 1

Input:

5 5
3 0 0 0 0
0 0 1 0 0
0 0 2 0 0
0 0 0 0 0
0 3 0 0 3

Output:

1
0 0

Example 2

Input:

2 2
1 0
0 1

Output:

2
0 0
1 1

Example 3

Input:

1 1
0

Output:

0

Example notes

Example 1: only (0,0) is valid. Near (2,2), the non-corner cell (4,1) holds 3, which is greater than 2; the two 3s in the bottom row each fall within the other's comparison region, so neither is valid. Output the count 1 first, then 0 0.

Editorial

Loading solution…