Pagini recente » Cod sursa (job #65027) | Cod sursa (job #494423) | Cod sursa (job #2069230) | Cod sursa (job #522575) | Cod sursa (job #1366907)
#include <fstream>
#include <stack>
#include <string>
using namespace std;
ifstream fin("bmatrix.in");
ofstream fout("bmatrix.out");
const int nmax= 200;
int n, m;
int v[nmax+1][nmax+1];
int x[nmax+1], y[nmax+1], a[nmax+1];
stack <int> s;
void rotate( ) {
int aux[nmax+1][nmax+1];
for ( int i= 1; i<=n; ++i ) {
for ( int j= 1; j<=m; ++j ) {
aux[j][n-i+1]= v[i][j];
}
}
n= n+m; m= n-m; n= n-m;
for ( int i= 1; i<=n; ++i ) {
for ( int j= 1; j<=m; ++j ) {
v[i][j]= aux[i][j];
}
}
}
int maxarea( int x1, int x2 ) {
int ans= 0;
for ( int i= x1; i<=x2; ++i ) {
for ( int j= 1; j<=m; ++j ) {
if ( i==x1 ) a[j]= 0;
if ( v[i][j]==0 ) ++a[j];
else a[j]= 0;
}
for ( ; !s.empty(); s.pop() ) ;
for ( int j= 1; j<=m; ++j ) {
for ( ; !s.empty() && a[j]<=a[s.top()]; s.pop() ) ;
if ( s.empty() ) x[j]= 1;
else x[j]= s.top()+1;
s.push(j);
}
for ( ; !s.empty(); s.pop() ) ;
for ( int j= m; j>=1; --j ) {
for ( ; !s.empty() && a[j]<=a[s.top()]; s.pop() ) ;
if ( s.empty() ) y[j]= m;
else y[j]= s.top()-1;
s.push(j);
ans= max(ans, a[j]*(y[j]-x[j]+1));
}
}
return ans;
}
int solve( ) {
int ans= 0;
for ( int i= 2; i<=n; ++i ) {
int max1= maxarea(1, i-1), max2= maxarea(i, n);
if ( max1*max2!=0 && ans<max1+max2 ) {
ans= max1+max2;
}
}
return ans;
}
int main( ) {
fin>>n>>m;
for ( int i= 1; i<=n; ++i ) {
string s;
fin>>s;
for ( int j= 1; j<=m; ++j ) {
v[i][j]= s[j-1]-'0';
}
}
int sol1= solve(), sol2, sol;
rotate();
sol2= solve();
sol= max(sol1, sol2);
fout<<sol<<"\n";
return 0;
}