Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp sort

Source: Internet
Author: User

B. Maximum Submatrix 2

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/problemset/problem/375/B

Descriptionyou is given a matrix consisting of digits zero and one, it size is NXM. You is allowed to rearrange its rows. What's the maximum area of the Submatrix, only consists of ones and can being obtained in the given problem by the DESCR ibed operations?

Let's assume that the rows of matrix A is numbered from 1 to n from top to bottom and the columns is numbered from 1 to M from left to right. A matrix Cell on the intersection of the i-th row and the J-th column can represented as (I, J). Formally, a submatrix of matrix A is a group of four integers D, U, L, R (1≤d≤u≤n; 1≤l≤r≤m). We'll assume that the Submatrix contains cells (i, j) (D≤i≤u; l≤j≤r). The area of the Submatrix is the number of cells it contains.

Input

The first line contains the integers n and M (1≤n, m≤5000). Next n lines contain m characters each-matrix a. 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.

Sample Input

1 1
1

Sample Output

1

HINT

Test instructions

Give you a 01 matrix, where you can swap positions between rows and rows

And ask you what the area of the rectangle that makes up the largest 1 is

Exercises

Let's take a look at this, first we preprocess

DP[I][J] means that the first row J of column I to the left furthest can extend how far

Because the columns are immutable, we sort each column and then use the DP idea to look down

Break when you get to dp[i][j]==0, because obviously the rest is 0.

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 5005#defineMoD 10007#defineEPS 1e-5Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************CharS[MAXN][MAXN];intDP[MAXN][MAXN];BOOLcmpintAintb) {    returnA>b;}intMain () {intN=read (), m=read (); intans=0;  for(intI=1; i<=n;i++) scanf ("%s", s[i]+1);  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++)            if(s[i][j]=='1') Dp[j][i]=dp[j-1][i]+1;  for(intI=1; i<=m;i++) {sort (Dp[i]+1, dp[i]+1+n,cmp);  for(intj=1; j<=n;j++)        {            if(dp[i][j]==0)                 Break; Ans=max (dp[i][j]*J,ans); }} cout<<ans<<Endl;}

Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.