# Cod sursa(job #18475)

Utilizator Data 18 februarie 2007 12:21:09 Zone 0 fpc done preONI 2007, Runda 2, Clasa a 9-a si gimnaziu 1.08 kb
``````var f,g:text;
n,i,j,k,l1,c1,l2,c2:longint;
s:array[1..1000] of longint;
a,b:array[1..500,1..500] of longint;
ok:boolean;
begin
assign(f,'zone.in');reset(f);
assign(g,'zone.out');rewrite(g);
for i:=1 to 9 do
c[i]:=i;
for i:=1 to 9 do
if c[i]<2 then inc(c[i]);
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];
ok:=true;
for k:=1 to 9 do
for i:=1 to n do
for j:=1 to n do
f (s[k]=b[i,j]) and (ok) then begin ok:=false; c1:=j;l1:=i;s[k]:=-1; end;
ok:=true;
for k:=1 to 9 do
for i:=l1+1 to n do
if (s[k]=b[i,c1]-b[l1,c1]) and (ok) then begin ok:=false; l2:=i; s[k]:=-1; end;
ok:=true;
for k:=1 to 9 do
for j:=c1+1 to n do
if (s[k]=b[l1,j]-b[l1,c1]) and (ok) then begin ok:=false; c2:=j; s[k]:=-1; end;
write(g,l1,' ',l2,' ',c1,' ',c2);
close(f);
close(g);
end.

``````