Cod sursa(job #958096)
Utilizator | Data | 6 iunie 2013 22:03:44 | |
---|---|---|---|
Problema | Castel | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.72 kb |
var a,b:array[0..151,0..151] of integer;
vcx,vcy:array[1..22500] of longint;
i,j,n,m,x,y,h,k,nr:longint;
f,g:text;
ok:boolean;
v:array[1..22500] of longint;
procedure vecini(n1,n2:longint);
begin
if v[a[n1,n2]]=1 then
begin
if b[n1,n2]=0 then
begin
ok:=true;
inc(h);
vcx[h]:=n1;
vcy[h]:=n2;
b[n1,n2]:=1;
nr:=(n1-1)*m+n2;
v[nr]:=1;
end;
end;
end;
begin
assign(f,'castel.in');
reset(f);
assign(g,'castel.out');
rewrite(g);
read(f,n,m,k);
for i:=1 to n do
for j:=1 to m do
read(f,a[i,j]);
for i:=1 to n do
begin
a[i,0]:=-1;
a[i,m+1]:=-1;
end;
for i:=1 to m do
begin
a[0,i]:=-1;
a[n+1,i]:=-1;
end;
x:=(k-1+m) div m;
y:=k mod m;
if y=0 then y:=m;
vcx[1]:=x;
vcy[1]:=y;
b[x,y]:=1;
h:=1;
v[k]:=1;
ok:=true;
while ok=true do
begin
ok:=false;
i:=0;
while i<h do
begin
inc(i);
vecini(vcx[i]-1,vcy[i]);
vecini(vcx[i]+1,vcy[i]);
vecini(vcx[i],vcy[i]+1);
vecini(vcx[i],vcy[i]-1);
end;
end;
writeln(g,h);
close(f);
close(g);
end.