比赛 20091103 评测结果 AAAAAAAAAAA
题目名称 乳草的入侵 最终得分 100
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-03 09:20:12
显示代码纯文本
program milkweed;
var
  i,j,x,y,xm,ym,p,time:integer;
  sz:array[0..101,0..101]of char;
begin
  assign(input,'milkweed.in');
  assign(output,'milkweed.out');
  reset(input);
  rewrite(output);
  readln(x,y,xm,ym);
  ym:=y-ym+1;
  for i:=0 to 101 do
    for j:=0 to 101 do
      sz[i,j]:='*';
  for i:=1 to y do
  begin
    for j:=1 to x do
      read(sz[i,j]);
    readln;
  end;
  sz[ym,xm]:='m';
  time:=0;
  while true do
  begin
    p:=0;
    time:=time+1;
    for i:=1 to y do
      for j:=1 to x do
      begin
        if sz[i,j]='m' then begin
          if sz[i-1,j]='.' then begin
            sz[i-1,j]:='x';
            p:=1;
          end;
          if sz[i-1,j-1]='.' then begin
            sz[i-1,j-1]:='x';
            p:=1;
          end;
          if sz[i-1,j+1]='.' then begin
            sz[i-1,j+1]:='x';
            p:=1;
          end;
          if sz[i+1,j]='.' then begin
            sz[i+1,j]:='x';
            p:=1;
          end;
          if sz[i+1,j-1]='.' then begin
            sz[i+1,j-1]:='x';
            p:=1;
          end;
          if sz[i+1,j+1]='.' then begin
            sz[i+1,j+1]:='x';
            p:=1;
          end;
          if sz[i,j-1]='.' then begin
            sz[i,j-1]:='x';
            p:=1;
          end;
          if sz[i,j+1]='.' then begin
            sz[i,j+1]:='x';
            p:=1;
          end;
        end;
      end;
    for i:=1 to y do
      for j:=1 to x do
       if sz[i,j]='x' then sz[i,j]:='m';
    if p=0 then break;
  end;
  p:=0;
  for i:=1 to y do
    for j:=1 to x do
      if sz[i,j]='.' then p:=1;
  if p=1 then writeln(-1) else writeln(time-1);
  close(input);
  close(output);
end.