B. Maximum Submatrix 2Time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output
You are given a matrix consisting of digits zero and one, it size is n x m. 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 the matrixais numbered from 1 toNFrom top to bottom and the columns is numbered from 1 toM 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 ais 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.
Examplesinput
1 1
1
Output
1
Input
2 2
10
11
Output
2
Input
4 3
100
011
000
101
Output
2
Interchange line, Perfection 1 Sub-matrix Max
DP pretreatment a[i][j] i row J column to the right there are several consecutive 1
Enumeration starts with that column, sorts the rows by a, and Counts.
Sorting can be sorted by count, but time is not significantly improved
////main.cpp//cf375b////Created by Candy on 9/15/16.//copyright©2016 Candy. All Rights Reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intn=5005;intn,m,a[n][n],ans=0;Chars[n];intt[n],h[n],ne[n];intcou[n],srt[n];voidBuc () {memset (cou,0,sizeof(cou)); intv=n; for(intI=1; I<=n;i++) cou[t[i]]++; for(intI=1; I<=v;i++) cou[i]+=cou[i-1]; for(inti=n;i>=1; i--) {srt[cou[t[i]]--]=t[i]; }}intSolintJ) { intans=0; for(intI=1; I<=n;i++) t[i]=a[i][j]; //Sort (t+1,t+1+n);Buc (); for(inti=n;i>=1; i--) ans=max (ans, (n-i+1)*srt[i]); returnans;}intMainintargcConst Char*Argv[]) {SCANF ("%d%d",&n,&m); for(intI=1; i<=n;i++) {scanf ("%s", s); for(intj=m-1; j>=0; j--){ if(s[j]=='1') a[i][j+1]=a[i][j+2]+1; Elsea[i][j+1]=0; } } for(intj=1; j<=m;j++) ans=Max (ans,sol (j)); printf ("%d", ans); return 0;}
CF 375B Maximum Submatrix 2[preprocessing Count sort]