1. 程式人生 > >10.30 POJ 3494

10.30 POJ 3494

http://poj.org/problem?id=3494
https://blog.csdn.net/zuzhiang/article/details/78136417

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
ll read()
{
	char ch=' ';
	ll f=1;ll x=0;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
	    x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
const ll N=2100;
ll a[N];
ll l[N],r[N];
stack <ll> s;
void init()
{
	while(!s.empty())
	{
		s.pop();
	}
}
int main()
{
	ll n,m;
	ll i,j;
	ll x;
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		ll ans=0;
		memset(a,0,sizeof(a));
		a[0]=-1;a[n+1]=-1;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				x=read();
				if(x==1)	a[j]+=1;
				else	a[j]=0;
			}
			init();
			for(j=1;j<=n+1;j++)
			{
				while(!s.empty()&&a[j]<a[s.top()])
				{
					r[s.top()]=j;
					s.pop();
				}
				s.push(j);
			}
			init();
			for(j=n;j>=0;j--)
			{
				while(!s.empty()&&a[j]<a[s.top()])
				{
					l[s.top()]=j;
					s.pop();
				}
				s.push(j);
			}
			ll sum=0;
			for(j=1;j<=n;j++)
			{
				sum=max(sum,(r[j]-1-l[j]-1+1)*a[j]);
			}
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
	}
	return 0;
}