#C5485. Largest Rectangle in a Binary Grid

    ID: 49139 Type: Default 1000ms 256MiB

Largest Rectangle in a Binary Grid

Largest Rectangle in a Binary Grid

You are given a binary grid with R rows and C columns. Each cell in the grid is either 0 or 1. Your task is to find the largest rectangular area consisting entirely of 1's and output its area.

The area of a rectangle is computed as \(A = w \times h\), where \(w\) and \(h\) are, respectively, the width and height of the rectangle.

If the grid is empty or contains no 1's, the output should be 0.

Note: A rectangle is defined as a contiguous block of cells aligned with the grid.

inputFormat

The input is given from standard input (stdin). The first line contains two integers R and C separated by a space, representing the number of rows and columns respectively. Each of the next R lines contains C integers (either 0 or 1) separated by spaces representing a row of the grid.

outputFormat

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

4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
6