#K8556. Largest Fertile Rectangle

    ID: 36668 Type: Default 1000ms 256MiB

Largest Fertile Rectangle

Largest Fertile Rectangle

Given a grid of size \( n \times m \), where each cell is represented by either '1' (fertile land) or '0' (barren land), your task is to find the area of the largest contiguous rectangle containing only '1's. This problem can be reduced to iteratively computing the maximum rectangle area in a histogram for each row.

Note that the rectangle must consist of consecutive cells in both dimensions. Use efficient techniques to handle larger grids.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains two integers \( n \) and \( m \), representing the number of rows and columns of the grid respectively.
  • The following \( n \) lines each contain a string of length \( m \) composed of characters '0' and '1'.

outputFormat

Output a single integer to standard output (stdout) representing the area of the largest rectangle comprised entirely of '1's.

## sample
4 5
10100
10111
11111
10010
6