Cod sursa(job #636377)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 19 noiembrie 2011 19:28:18
Problema DreptPal Scor 50
Compilator fpc Status done
Runda .com 2011 Marime 1.5 kb
Program dreptpal;
 var a,b:array [0..1000,0..1000] of longint;
     n,m,i,j,s,nr,max,k,x,y,hs,hj:longint;
     fi,fo:text;
procedure solvesus(c:integer);
 var d,f:integer;
begin
 d:=x+1; f:=y-1;
  while (a[c,d]=a[c,f]) and (d<f) do begin inc(d); dec(f); end;
 if d=f then begin
              inc(hs);
              b[c,x+1]:=1; b[c,y-1]:=1;
               if c>1 then solvesus(c-1);
               end;
end;
procedure solvejos(c:integer);
 var d,f:integer;
begin
 d:=x+1; f:=y-1;
  while (a[c,d]=a[c,f]) and (d<f) do begin inc(d); dec(f); end;
 if d=f then begin
              inc(hj);
              b[c,x+1]:=1; b[c,y-1]:=1;
               if c<n then solvejos(c+1);
               end;
end;
procedure control();
begin
 x:=j-1; y:=j+1; hs:=0; hj:=0;
  while (a[i,x]=a[i,y]) and (x>=1) and (y<=m) do begin
                                           dec(x); inc(y);
                                                end;
if (b[i,x+1]<>1) or (b[i,y-1]<>1) then begin
      if i>1 then solvesus(i-1);
       if i<n then solvejos(i+1);
        if (hs+hj+1)*(y-x-1)>max then max:=(hs+hj+1)*(y-x-1);
         end;
b[i,x+1]:=1; b[i,y-1]:=1;
end;
begin
 assign(fi,'dreptpal.in');
  assign(fo,'dreptpal.out');
 reset(fi); rewrite(fo);
 readln(fi,n,m);
 if n>m then max:=n else max:=m;
  for i:=1 to n do begin
   for j:=1 to m do begin read(fi,a[i,j]); end;
    readln(fi);
  end;
  for i:=1 to n do
   for j:=2 to m-1 do
    if a[i,j-1]=a[i,j+1] then control();
 write(fo,max);
close(fo);
end.