ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1250. Sea Burial

What's wrong with that code ?? -> it's so obvious
Posted by uuuuuuu 16 Mar 2003 21:02
var
mapa:array[0..501,0..501]of -2..1;
x,y,wsp1,wsp2:longint;
ilewysp:longint;

procedure wczytaj;
var i,j:longint;
    zn:char;
    zb:text;
begin
 {assign(zb,'1250.in');
 reset(zb);     }
 readln({zb,}x,y,wsp1,wsp2);
 for i:=1 to y do
 begin
  for j:=1 to x do
   begin
   read({zb,}zn);
   if zn='#'then mapa[i,j]:=1
   end;
 readln{(zb)}
 end;
{close(zb)}
end;

procedure zaznacz(a,b:longint);
begin
mapa[a,b]:=-2;
 if (a-1>0)and(mapa[a-1,b]>0)then zaznacz(a-1,b);
 if (a+1<=x)and(mapa[a+1,b]>0)then zaznacz(a+1,b);
 if (b-1>0)and(mapa[a,b-1]>0)then zaznacz(a,b-1);
 if (b+1<=y)and(mapa[a,b+1]>0)then zaznacz(a,b+1);
end;

procedure sprawdz(a,b:longint);
begin
mapa[a,b]:=-2;
 if (a-1>0)and(mapa[a-1,b]>0)then zaznacz(a-1,b);
 if (a+1<=x)and(mapa[a+1,b]>0)then zaznacz(a+1,b);
 if (b-1>0)and(mapa[a,b-1]>0)then zaznacz(a,b-1);
 if (b+1<=y)and(mapa[a,b+1]>0)then zaznacz(a,b+1);
inc(ilewysp)
end;

procedure dfs(a,b:longint);
begin
mapa[a,b]:=-1;
 if (a-1>0)and(mapa[a-1,b]=0)then dfs(a-1,b)
 else if (a-1>0)and(mapa[a-1,b]=1)then sprawdz(a-1,b);

 if (a+1<=x)and(mapa[a+1,b]=0)then dfs(a+1,b)
 else if (a+1<=x)and(mapa[a+1,b]=1)then sprawdz(a+1,b);

 if (b-1>0)and(mapa[a,b-1]=0)then dfs(a,b-1)
 else if (b-1>0)and(mapa[a,b-1]=1)then sprawdz(a,b-1);

 if (b+1<=y)and(mapa[a,b+1]=0)then dfs(a,b+1)
 else if (b+1<=y)and(mapa[a,b+1]=1)then sprawdz(a,b+1);
end;

begin
while not eof do
begin
fillchar(mapa,sizeof(mapa),0);
wczytaj;
dfs(wsp1,wsp2);
writeln(ilewysp)
end
end.