UberOA #57
Regional Maximum Finder
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationIn-place Arrays
For a non-zero cell (i,j), its value v also serves as a radius, and its region is [i−v,i+v]×[j−v,j+v] with the four original corner points removed and any out-of-bounds part ignored. A cell is a region maximum if its value equals the maximum over its region; tied maximums are all kept. Return all such cells in any order.
This site has made the standard input and output explicit.
Input
The first line contains n m, followed by n lines of m integers. On this site 1≤n,m≤100 and 0≤value≤10⁹.
Output
First output the number of cells k, then k pairs of 0-based row and column coordinates, in any order and without duplicates.
Example 1
Input:
3 3
3 0 1
2 0 0
0 0 0
Output:
2
0 0
0 2
Example 2
Input:
2 2
1 9
0 1
Output:
1
0 1
Example 3
Input:
2 2
2 2
2 2
Output:
4
0 0
0 1
1 0
1 1
Example notes
Example 1: only the 3 at (0,0) and the 1 at (0,2) qualify. Example 2: the 9 at (0,1) is the largest; both regions of the two 1s contain it, and it is not an original corner, so only (0,1) qualifies. Example 3: all four cells tie for the maximum, so output all of them, in any order.
Editorial
Loading solution…