Cod sursa(job #637518)

Utilizator mihaipopa12Popa Mihai mihaipopa12 Data 20 noiembrie 2011 15:00:54
Problema DreptPal Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.85 kb
#include<stdio.h>

#define fsize 7000000
#define maxn 1005

FILE*f=fopen("dreptpal.in","r");
FILE*g=fopen("dreptpal.out","w");

int n,m,i,j,ch,lenght,p,u;
int A[maxn][maxn],D[maxn][maxn];
char buff[fsize];

inline int next () {
	int r = 0;
	while ( buff[ch] >= '0' && buff[ch] <= '9' && ch <= lenght ){
		r = r * 10 + buff[ch] - '0';
		++ch;
	}
	++ch;
	return r;
}

int main () {
	
	
	lenght = fread(buff+1,1,fsize-5,f); ch = 1;
	n = next(); m = next();
	
	for ( i = 1 ; i <= n ; ++i ){
		for ( j = 1 ; j <= m ; ++j ){
			A[i][j] = next();
		}
	}
	
	for ( i = 1 ; i <= n ; ++i ){
		for ( j = 1 ; j <= m ; ++j ){
			p = u = j;
			while ( 1 ){
				if ( !p || u > m || A[i][p] != A[i][u] )	break ;
				if ( D[i][u] < u - p + 1 )
					D[i][u] = u - p + 1;
				--p; ++u;
			}
		}
	}
	
	fclose(f);
	fclose(g);
	
	return 0;
}