Cod sursa(job #2184828)

Utilizator MDiana15Diana M MDiana15 Data 24 martie 2018 11:24:18
Problema BMatrix Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <fstream>
#include <iostream>
#define INF 40005
using namespace std;
ifstream f("bmatrix.in");
ofstream g("bmatrix.out");
int n,m,i,j,x,y,st[205],dr[205],sus[205],jos[205],a[205],l,ss;
char v[205][205];
int main()
{
   f>>n>>m;
   for(i=1;i<=n;i++)
      for(j=1;j<=m;j++)
        f>>v[i][j];

    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++)
        {
            if(v[i][j]=='0')a[j]++;
            else a[j]=0;
            x=INF;
            y=0;
            for(l=j; l>=1; l--)
            {
                x=min(x,a[l]);
                y=max(y,x*(j-l+1));
            }
            st[i]=max(st[i],max(st[i-1],y));
            sus[j]=max(sus[j],max(sus[j-1],y));
        }
    for(i=1;i<=m;i++)a[i]=0;

    for(i=n; i>=1; i--)
        for(j=m; j>=1; j--)
        {
            if(v[i][j]=='0')a[j]++;
            else a[j]=0;
            x=INF;
            y=0;
            for(l=j; l<=m; l++)
            {
                x=min(x,a[l]);
                y=max(y,x*(l-j+1));
            }
            dr[i]=max(dr[i],max(dr[i+1],y));
            jos[j]=max(jos[j],max(jos[j+1],y));
        }
    for(i=1; i<=n; i++)
    {
        ss=max(ss,st[i]+dr[i+1]);
    }
    for(i=1; i<=m; i++)
    {
        ss=max(ss,sus[i]+jos[i+1]);
    }
    g<<ss;
    return 0;
}