Cod sursa(job #636540)

Utilizator maritimCristian Lambru maritim Data 19 noiembrie 2011 21:07:29
Problema DreptPal Scor 10
Compilator cpp Status done
Runda .com 2011 Marime 1.23 kb
#include<stdio.h>
#include<algorithm>
using namespace std;

#define MaxN 1100
#define ll long long

int N,M,MAX = 0,A[MaxN][MaxN],B[MaxN][MaxN],C[MaxN];

void citire(void)
{
	FILE *f = fopen("dreptpal.in","r");
	
	fscanf(f,"%d %d",&N,&M);
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++)
			fscanf(f,"%ld ",&A[i][j]);
	
	fclose(f);
}

void Bb(void)
{
	int k = 0;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++)
		{
			for(k = 1;A[i][j-k] == A[i][j+k] && j-k && j+k <= M;k++);
			B[i][j] = 1 + 2*(k-1);
		}
}

int cmp(int a,int b)
{
	return a > b;
}

int Min(void)
{
	int MIN = 223321;
	for(int i=1;i<=N;i++)
		if(C[i] < MIN && C[i])
			MIN = C[i];
	return (MIN != 223321) ? MIN:0;
}

void Max(void)
{
	int MIN,MIN2,l = 0;
	for(int i=1;i<=M;i++)
	{
		MIN2 = l = 0;
		for(int j=1;j<=N;j++)
			C[j] = B[j][i];
		MIN = Min();
		while(MIN)
		{
			l = 0;
			for(int j=1;j<=N;j++)
			{
				if(C[j])
				{
					C[j] -= MIN;
					if((MIN+MIN2)*(++l) > MAX)
						MAX = (MIN+MIN2)*l;
				}
				else
					l = 0;
			}
			MIN2 = MIN;
			MIN = Min();
		}
	}
}

int main()
{
	FILE *g = fopen("dreptpal.out","w");
	
	citire();
	Bb();
	Max();
	fprintf(g,"%d ",MAX);
	
	fclose(g);
	return 0;
}