Cod sursa(job #635644)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 19 noiembrie 2011 13:47:00
Problema DreptPal Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.97 kb
#include <stdio.h>
#include <fstream>
#include <algorithm>
using namespace std;

const int dim = 1005;
int N, M, C, S[dim], A[dim][dim]; 

void cit ()
{
	scanf ("%d%d", &N, &M);
	
	int i, j;
	for (i = 0; i < N; i++)
	{
		scanf ("%d", &S[0]);
		A[i][0] = 1;		
		for (j = 1; j < M; j++)
		{
			scanf ("%d", &S[j]);			
			A[i][j] = A[i][j-1] + 2;
			/*
			if (j-A[i][j]+1 >= 0 && S[j] == S[j-A[i][j]+1])
				A[i][j] += 2;
			*/
			while ((j-A[i][j]+1 < 0 || S[j] != S[j-A[i][j]+1]) && A[i][j] != 1)
				A[i][j] -= 2;
		}
	}
}

int parc (int j)
{
	int sc = A[0][j], sm = A[0][j];
	for (int i = 1; i < N; i++)
	{
		if (A[i-1][j] == A[i][j])
			sc += A[i][j];
		else
			sc = A[i][j];
		sm = max (sm, sc);
	}
	return sm;
}

int main ()
{
	freopen ("dreptpal.in", "r", stdin);
	freopen ("dreptpal.out", "w", stdout);
	
	cit ();
	for (int j = 0, x; j < M; j++)
	{
		x = parc (j);
		C = max (C, x);
	}
	printf ("%d\n", C);
	
	return 0;
}