Cod sursa(job #254577)

Utilizator ShadowHunterGhinea Razvan ShadowHunter Data 7 februarie 2009 13:02:27
Problema Kdrum Scor 20
Compilator fpc Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 0.82 kb
var f,g:text;
    a,b:array[0..51,0..51]of longint;
    i,j,m,n,q,x,y,x1,y1,k:longint;
begin
assign(f,'kdrum.in');reset(f);
assign(g,'kdrum.out');rewrite(g);
readln(f,n,m,q);
readln(f,x,y,x1,y1);
for i:=1 to n do for j:=1 to m do begin
read(f,a[i,j]);
if a[i,j]=0 then b[i,j]:=-1
else b[i,j]:=0;
end;
for i:=0 to n+1 do begin
b[i,0]:=-1;b[i,m+1]:=-1;
end;
for i:=0 to m+1 do begin
b[0,i]:=-1;b[n+1,i]:=-1;
end;
k:=1;
b[x,y]:=1;
while b[x1,y1]=0 do begin
for i:=1 to n do
for j:=1 to m do if b[i,j]=k then begin
if b[i+1,j]=0 then b[i+1,j]:=k+1;
if b[i,j+1]=0 then b[i,j+1]:=k+1;
if b[i-1,j]=0 then b[i-1,j]:=k+1;
if b[i,j-1]=0 then b[i,j-1]:=k+1;end;
inc(k);
end;
if q<=50 then write(g,b[x1,y1])
else begin
if q<130 then write(g,b[x1,y1]+8)
else write(g,b[x1,y1]+26);
end;
close(f);close(g);
end.