#K52602. Largest Grass Rectangle
Largest Grass Rectangle
Largest Grass Rectangle
You are given a grid representing a field with N rows and M columns. Each cell in the grid is marked with a character. A cell marked with G
represents grass, while any other character (for example, R
or .
) represents an obstacle.
Your task is to find the area of the largest rectangular sub-grid that consists entirely of grass cells. In other words, you need to find the maximum area of a rectangle such that every cell within it is G
. The area is calculated by the formula: \( \text{area} = \text{height} \times \text{width} \).
The following constraints apply:
- The input is read from standard input (stdin).
- The output, which is the maximum area, is written to standard output (stdout). </p>
- A line containing two space-separated integers, \(N\) and \(M\), representing the number of rows and columns, respectively.
- Following this, there are \(N\) lines, each containing \(M\) characters separated by spaces. Each character is either
G
(grass) or another character (indicating an obstacle).
inputFormat
The input consists of:
For example:
4 5 G . G G G . G . . . G G G R R G G G G G
outputFormat
Output a single integer: the area of the largest rectangle that can be formed using only grass cells (G
).
4 5
G . G G G
. G . . .
G G G R R
G G G G G
6