Maximum Submatrix 2

来源:互联网 发布:手机虚拟按键软件 编辑:程序博客网 时间:2024/05/22 00:27

You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?

Let's assume that the rows of matrix a are numbered from 1 ton from top to bottom and the columns are numbered from 1 tom from left to right. A matrix cell on the intersection of thei-th row and the j-th column can be represented as(i, j). Formally, a submatrix of matrixa is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells(i, j) (d ≤ i ≤ ul ≤ j ≤ r). The area of the submatrix is the number of cells it contains.

Input

The first line contains two integers n andm (1 ≤ n, m ≤ 5000). Nextn lines contain m characters each — matrixa. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.

Output

Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.

Example



Input

1 11

Output

1

Input

2 21011

Output

2

Input

4 3100011000101

Output

2

题意

给你一个01矩阵,行与行之间可以交换位置

然后问你构成构成最大的只含1的矩形的面积是多少

题解:

我们分析一下,首先我们预处理一下

dp[i][j]表示第i列第j行往左边最远能延长多远

因为列是不会变的,所以我们对于每一列都排序,然后利用dp的思想往下找

到dp[i][j]==0的时候break,因为显然剩下的都是0了

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char map[5500][5500];int h[5500][5500],n,m,ans=0;bool cmp(int a,int b){    return a>b;}int main(){    scanf("%d%d",&n,&m);    for(int i=1;i<=n;i++) scanf("%s",map[i]+1);    for(int i=1;i<=n;i++)    {        for(int j=1;j<=m;j++)        {            if(map[i][j]=='1') h[j][i]=h[j-1][i]+1;        }    }    for(int i=1;i<=m;i++)    {        sort(h[i]+1,h[i]+n+1,cmp);        for(int j=1;j<=n;j++)        {            if(h[i][j]==0) break;            ans=max(ans,h[i][j]*j);        }    }    printf("%d\n",ans);}

1 0
原创粉丝点击