#K38827. Maximal Forest Rectangle
Maximal Forest Rectangle
Maximal Forest Rectangle
You are given a grid of r rows and c columns. Each cell of the grid contains a character. A cell marked with 'F'
represents a forest tile, while any other character represents a non-forest tile.
Your task is to compute the area of the largest rectangle (aligned with the grid) that can be formed using only forest tiles. In other words, you should find the maximal number of contiguous cells forming a rectangle, all of which are 'F'
.
The problem can also be described using the following formula in LaTeX:
\( \text{Max Area} = \max_{\substack{1 \leq i \leq j \leq r \ 1 \leq k \leq l \leq c}} \{(j-i+1) \times (l-k+1) \ \text{ such that every cell } (p,q)\ in\ [i,j]\times[k,l]\ is\ 'F'\} \)
Note that the rectangle must be contiguous and aligned with the grid rows and columns.
inputFormat
The input is read from stdin and has the following format:
- The first line contains two space-separated integers
r
andc
, wherer
is the number of rows andc
is the number of columns. - This is followed by
r
lines, each containing a string of lengthc
representing a row of the grid.
outputFormat
Output to stdout a single integer, which is the area of the largest rectangle composed entirely of forest tiles ('F'
).
3 3
WFW
FWF
FFF
3