← 返回 waymo 的题目列表Max Pooling with Argmax Coordinates
类型:online_judge
Problem: Implement 2D Max Pooling and Return Argmax Coordinates
Given an integer matrix grid of size H x W, a pooling window size kH x kW, and strides sH, sW.
Implement 2D max pooling: for every valid window, output the maximum value inside that window.
As a follow-up, for each window, also output the coordinate (row, col) of the maximum value in the original matrix grid. Coordinates are 0-indexed.
If there are multiple cells with the same maximum value in a window, return the lexicographically smallest coordinate: smallest row first, then smallest col.
No padding is used. Only windows fully contained in the matrix are considered.
Output Size
outH = floor((H - kH) / sH) + 1
outW = floor((W - kW) / sW) + 1
It is guaranteed that H >= kH and W >= kW.
Input Format
H W kH kW sH sW
grid[0][0] grid[0][1] ... grid[0][W-1]
...
grid[H-1][0] ... grid[H-1][W-1]
Output Format
First print:
outH outW
Then print outH rows, each containing outW integers: the max-pooled values.
Then print outH rows, each containing outW coordinates in the format (r,c): the argmax coordinates in the original matrix.
Constraints
1 <= H, W <= 500
1 <= kH <= H
1 <= kW <= W
1 <= sH, sW <= 500
-10^9 <= grid[i][j] <= 10^9
Example
Input:
4 4 2 2 2 2
1 3 2 4
5 6 1 2
7 8 9 0
1 2 3 4
Output:
2 2
6 4
8 9
(1,1) (0,3)
(2,1) (2,2)
Example
Input
4 4 2 2 2 2
1 3 2 4
5 6 1 2
7 8 9 0
1 2 3 4
Output
2 2
6 4
8 9
(1,1) (0,3)
(2,1) (2,2)