#K39962. Maximal Rectangle in a Binary Matrix

    ID: 26537 Type: Default 1000ms 256MiB

Maximal Rectangle in a Binary Matrix

Maximal Rectangle in a Binary Matrix

You are given a binary matrix (a 2D array filled with 0s and 1s) with dimensions \( m \times n \). Your task is to compute the area of the largest rectangle containing only 1s within this matrix.

More formally, given a binary matrix \( matrix \), find the maximum area of a rectangle consisting solely of 1s. If the matrix is empty or no such rectangle exists, output 0.

Note: The input is read from stdin and the output should be printed to stdout.

Example:

Input:
4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Output: 6

</p>

inputFormat

The input is provided via stdin in the following format:

  1. The first line contains two integers \( m \) and \( n \) separated by a space, representing the number of rows and columns of the matrix.
  2. The next \( m \) lines each contain \( n \) space-separated integers (each either 0 or 1) representing the binary matrix.

If \( m = 0 \), the matrix is empty.

outputFormat

Output a single integer representing the area of the largest rectangle that can be formed with 1s. The result should be printed to stdout.

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