#K44277. Maximum Rectangular Area with Uniform Height

    ID: 27496 Type: Default 1000ms 256MiB

Maximum Rectangular Area with Uniform Height

Maximum Rectangular Area with Uniform Height

In this problem, you are given one or more grids which represent a terrain map where each cell has an integer height. Your task is to find the maximum area of a contiguous rectangular sub-grid where all the cells share the same height. In other words, for each test case, determine the rectangle (aligned with the grid) such that every cell inside it has an identical value, and its area is maximized.

More formally, given a grid of size (N \times M) with integer values, find the maximum area among all rectangular regions where every element in the region is equal. The area of a rectangle is defined as (\text{area} = \text{height} \times \text{width}).

inputFormat

The input begins with an integer (T) representing the number of test cases. For each test case, the first line contains two integers (N) and (M) representing the dimensions of the grid. The next (N) lines each contains (M) space-separated integers indicating the heights of the cells.

Example:

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

outputFormat

For each test case, output a single integer on a new line representing the maximum area of a rectangular region within the grid where all cells have the same height.

Example:

3
20
## sample
2
3 3
1 2 1
2 2 2
1 2 1
4 5
3 3 3 3 3
3 3 3 3 3
3 3 3 3 3
3 3 3 3 3
3

20

</p>