Cod sursa(job #638035)

Utilizator ProcopliucProcopliuc Adrian Procopliuc Data 20 noiembrie 2011 18:18:22
Problema DreptPal Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.99 kb
# include <fstream>
using namespace std;
ifstream f ("dreptpal.in");
ofstream g ("dreptpal.out");
int a[1005][1005],i,j,n,m,maxim,x,lg[1005][1005],h[1005][1005];

int calc (int i,int j)
{
	int i1=1,j1=1,mm=0,nmax=10000;
	
	while (a[i][j+j1]==a[i][j-j1] && j-j1>=1 && j+j1<=m)
	{
		i1=1;
		if (lg[i+i1][j-j1]==2*j1+1)
		{
			mm=lg[i+i1][j-j1]*h[i+i1][j-j1];
			if (lg[i][j-j1]==0)
			lg[i][j-j1]=2*j1+1;
			if (h[i][j-j1]==0)
			h[i][j-j1]=h[i+i1][j-j1]+1;
		}
		
		else
		{
		while (a[i+i1][j+j1]==a[i+i1][j-j1] && i1<=nmax && i1+i<=n)
			i1++;
		nmax=i1-1;
		
		
		if (mm<(2*j1+1)*(nmax+1))
			mm=(2*j1+1)*(nmax+1);
		
		if (lg[i][j-j1]==0)
		lg[i][j-j1]=2*j1+1;
		if (h[i][j-j1]==0)
		h[i][j-j1]=nmax+1;
		
		}
	j1++;
	}
	return mm;
}


int main ()
{
	f>>n>>m;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			f>>a[i][j];
		
	for (i=n;i>=1;i--)
		for (j=m;j>=1;j--)
		{
			x=calc (i,j);
			if (maxim<x)
				maxim=x;
		}
		
	g<<maxim;
	return 0;
	
}