#C7575. Largest Fertile Rectangle
Largest Fertile Rectangle
Largest Fertile Rectangle
Farmer Jane owns a large farm where each plot is either fertile (denoted by '1') or barren (denoted by '0'). Her goal is to locate the largest rectangular area that is completely fertile. In other words, you are given a binary grid and you need to find the maximum area of a subrectangle that contains only '1's.
The area of a rectangle is computed as (\text{area} = \text{height} \times \text{width}). An efficient approach is to treat each row as the base of a histogram and then apply a stack-based method to compute the maximal rectangle under the histogram.
inputFormat
The input is read from stdin. The first line contains an integer ( m ) representing the number of rows in the grid. Each of the following ( m ) lines contains a binary string of equal length where each character is either '0' or '1'.
outputFormat
Output a single integer to stdout representing the maximum area of a rectangular region that contains only fertile plots ('1's).## sample
4
10100
10111
11111
10010
6