# Cod sursa(job #18434)

Utilizator Data 18 februarie 2007 12:12:08 Zone 40 fpc done preONI 2007, Runda 2, Clasa a 9-a si gimnaziu 0.96 kb
``````var f,g:text;
n,i,j,k,l1,c1,l2,c2:longint;
m:array[1..1000] of longint;
a,b:array[1..500,1..500] of longint;
h:boolean;
begin
assign(f,'zone.in');reset(f);
assign(g,'zone.out');rewrite(g);
for i:=1 to 9 do
for i:=1 to n do
for j:=1 to n do
b[1,1]:=a[1,1];
for i:=2 to n do
b[i,1]:=b[i-1,1]+a[i,1];
for j:=2 to n do
b[1,j]:=b[1,j-1]+a[1,j];
for i:=2 to n do
for j:=2 to n do
b[i,j]:=a[i,j]+b[i-1,j]+b[i,j-1]-b[i-1,j-1];
h:=true;
for k:=1 to 9 do
for i:=1 to n do
for j:=1 to n do
if (m[k]=b[i,j]) and (h) then begin h:=false; c1:=j;l1:=i;m[k]:=-1; end;
h:=true;
for k:=1 to 9 do
for i:=l1+1 to n do
if (m[k]=b[i,c1]-b[l1,c1]) and (h) then begin h:=false; l2:=i; m[k]:=-1; end;
h:=true;
for k:=1 to 9 do
for j:=c1+1 to n do
if (m[k]=b[l1,j]-b[l1,c1]) and (h) then begin h:=false; c2:=j; m[k]:=-1; end;
write(g,l1,' ',l2,' ',c1,' ',c2);
close(f);
close(g);

end.

``````