Cod sursa(job #1297990)

Utilizator musashi1Doros Doru-Lucian musashi1 Data 22 decembrie 2014 14:40:23
Problema Teren Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.71 kb
var n,m,i,j,ii,jj,x,p,s,u,smax:integer;
f,g:text;
a:array[1..300,1..300]of integer;

begin

assign(f,'teren.in'); reset(f);
assign(g,'teren.out'); rewrite(g);

read(f,n);
read(f,m);
read(f,x);
for i:=1 to n do begin
 for j:=1 to m do begin
 read(f,a[i,j]);
 end;
end;

smax:=0;

for i:=1 to n do begin
 for j:=1 to m do begin
 if a[i,j]=1 then u:=1 else u:=0;
 ii:=1;
 while (u<=x) and (i+ii<=n) and (j+ii<=m) do begin
 for jj:=1 to ii do begin
  if a[i+ii,j+jj-1]=1 then u:=u+1;
  if a[i+jj-1,j+ii]=1 then u:=u+1;
 end;
 if a[i+ii,j+ii]=1 then u:=u+1;
 if u<=x then ii:=ii+1;
 end;
 ii:=ii;
 s:=ii*ii;
 if s>smax then smax:=s;

 end;
end;

write(g,smax);

close(f);
close(g);
end.