#K78217. Maximal Rectangle of Grassy Cells

    ID: 35038 Type: Default 1000ms 256MiB

Maximal Rectangle of Grassy Cells

Maximal Rectangle of Grassy Cells

You are given an n x n grid representing a garden. Each cell is either 0 (grassy) or 1 (waterlogged). Your task is to find the area of the largest rectangle (with sides parallel to the grid) that is composed entirely of grassy cells.

In other words, you need to compute the maximum number of contiguous 0 cells forming a rectangle within the grid. Use efficient algorithms such as the largest rectangle in a histogram technique to achieve this.

The area of a rectangle is defined as:

$$\text{Area} = \text{width} \times \text{height}$$

inputFormat

The input is given via standard input (stdin) with the following format:

  • The first line contains an integer n representing the size of the grid.
  • The next n lines each contain n space-separated integers (either 0 or 1) representing the grid cells.

outputFormat

Output a single integer representing the area of the largest rectangle composed entirely of grassy cells (0s). The output should be printed to standard output (stdout).

## sample
5
0 1 1 0 1
1 0 1 1 0
0 0 1 0 0
1 1 0 0 0
1 0 0 1 0
4