记录编号 15186 评测结果 AAAAAAAAAAA
题目名称 [USACO Oct09] 乳草的入侵 最终得分 100
用户昵称 Gravatarchengyang 是否通过 通过
代码语言 Pascal 运行时间 0.075 s
提交时间 2009-11-10 16:04:12 内存使用 0.12 MiB
显示代码纯文本
program milkweed;
var
  i,j,x,y,xx,yy,p,time:integer;
  a:array[0..101,0..101]of char;
begin
  assign(input,'milkweed.in');
  assign(output,'milkweed.out');
  reset(input);
  rewrite(output);
  
  readln(x,y,xx,yy);
  yy:=y-yy+1;
  
  for i:=0 to 101 do
    for j:=0 to 101 do
      a[i,j]:='*';
  for i:=1 to y do
  begin
    for j:=1 to x do
      read(a[i,j]);
    readln;
  end;
  
  a[yy,xx]:='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 a[i,j]='m' then begin
          if a[i-1,j]='.' then begin
            a[i-1,j]:='x';
            p:=1;
          end;
          if a[i-1,j-1]='.' then begin
            a[i-1,j-1]:='x';
            p:=1;
          end;
          if a[i-1,j+1]='.' then begin
            a[i-1,j+1]:='x';
            p:=1;
          end;
          if a[i+1,j]='.' then begin
            a[i+1,j]:='x';
            p:=1;
          end;
          if a[i+1,j-1]='.' then begin
            a[i+1,j-1]:='x';
            p:=1;
          end;
          if a[i+1,j+1]='.' then begin
            a[i+1,j+1]:='x';
            p:=1;
          end;
          if a[i,j-1]='.' then begin
            a[i,j-1]:='x';
            p:=1;
          end;
          if a[i,j+1]='.' then begin
            a[i,j+1]:='x';
            p:=1;
          end;
        end;
      end;
    for i:=1 to y do
      for j:=1 to x do
       if a[i,j]='x' then a[i,j]:='m';
    if p=0 then break;
  end;
  
  p:=0;
  for i:=1 to y do
    for j:=1 to x do
      if a[i,j]='.' then p:=1;
  if p=1 then writeln(-1) else writeln(time-1);
  
  close(input);
  close(output);
end.