记录编号 |
14725 |
评测结果 |
AAWAWAWAWAA |
题目名称 |
[USACO Oct09] 乳草的入侵 |
最终得分 |
63 |
用户昵称 |
ReimBurSe. |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.048 s |
提交时间 |
2009-11-03 17:37:12 |
内存使用 |
0.19 MiB |
显示代码纯文本
Program milkweed;
Type
sc=array [1..100,1..100] of longint;
Var
i,j:longint;
s,shizi:sc;
x,y:longint;
m,n,t:longint;
c:char;
o,o1,o2:boolean;
Begin
assign(input,'milkweed.in');
assign(output,'milkweed.out');
reset(input);
rewrite(output);
readln(n,m,y,x);
for i:=1 to m do
for j:=1 to n do
s[i,j]:=-2;
for i:=1 to m do begin
for j:=1 to n do begin
read(c);
if c='*' then s[i,j]:=-1;
end;
readln;
end;
x:=m-x+1;
s[x,y]:=0;
o:=true;
t:=0;
while o=true do begin
t:=t+1;
o1:=false;
for i:=1 to m do begin
for j:=1 to n do begin
if s[i,j]=t-1 then begin
if j-1>=1 then begin
if s[i,j-1]=-2 then begin
s[i,j-1]:=t;
o1:=true;
end;
end;
if j+1<=n then begin
if s[i,j+1]=-2 then begin
s[i,j+1]:=t;
o1:=true;
end;
end;
if (i-1)>=1 then begin
if s[i-1,j]=-2 then begin
s[i-1,j]:=t;
o1:=true;
end;
if j-1>=1 then begin
if s[i-1,j-1]=-2 then begin
s[i-1,j-1]:=t;
o1:=true;
end;
end;
if j+1<=n then begin
if s[i-1,j+1]=-2 then begin
s[i-1,j+1]:=t;
o1:=true;
end;
end;
end;
if (i+1)<=n then begin
if s[i+1,j]=-2 then begin
s[i+1,j]:=t;
o1:=true;
end;
if j-1>=1 then begin
if s[i+1,j-1]=-2 then begin
s[i+1,j-1]:=t;
o1:=true;
end;
end;
if j+1<=n then begin
if s[i+1,j+1]=-2 then begin
s[i+1,j+1]:=t;
o1:=true;
end;
end;
end;
end;
end;
end;
o2:=true;
for i:=1 to m do
for j:=1 to n do
if s[i,j]=-2 then o2:=false;
if o2=true then o:=false;
if (o1=false)and(o=true) then begin
writeln('-1');
close(input);
close(output);
halt;
end;
end;
writeln(t);
close(input);
close(output);
End.