#K67912. Maximal Rectangle in a Binary Matrix

    ID: 32748 Type: Default 1000ms 256MiB

Maximal Rectangle in a Binary Matrix

Maximal Rectangle in a Binary Matrix

Given a binary matrix of size (m \times n) containing only 0's and 1's, your task is to find the area of the largest rectangle that contains only 1's. The rectangle must be formed by contiguous cells and its area is defined as (width \times height).

For example, in the following matrix:
(\begin{bmatrix}1 & 0 & 1 & 0 & 0\ 1 & 0 & 1 & 1 & 1\ 1 & 1 & 1 & 1 & 1\ 1 & 0 & 0 & 1 & 0\end{bmatrix}) the maximum rectangle of 1's has an area of 6.

inputFormat

The first line contains two integers (m) and (n), representing the number of rows and columns, respectively. Following this are (m) lines, each containing (n) integers (each either 0 or 1) separated by spaces, representing the rows of the matrix.

outputFormat

Output a single integer representing the area of the largest rectangle containing only 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