记录编号 7042 评测结果 AAAAAAAAAA
题目名称 [USACO Dec08] 花园栅栏 最终得分 100
用户昵称 GravatarAchilles 是否通过 通过
代码语言 Pascal 运行时间 0.022 s
提交时间 2008-11-06 09:55:34 内存使用 0.13 MiB
显示代码纯文本
program fence;
var
  f:char;
  table:array[0..101,0..101]of 0..15;
  t2:array[0..101,0..101]of 0..1;
  x,y,z,i,j,l,p,max,maxt:integer;
procedure floodfill(x,y:integer);
var
  a:array[1..15000]of record
    x,y:integer;
  end;
  p1,p2:integer;
begin
  fillchar(a,sizeof(a),0);
  p1:=0;
  p2:=1;
  a[1].x:=x;
  a[1].y:=y;
  t2[x,y]:=1;
  max:=max+1;
  while p1<p2 do
  begin
    p1:=p1+1;
    if (a[p1].x+1<=101)and(table[a[p1].x,a[p1].y]and 1=0) then begin
      if t2[a[p1].x+1,a[p1].y]=0 then begin
        p2:=p2+1;
        a[p2].x:=a[p1].x+1;
        a[p2].y:=a[p1].y;
        t2[a[p2].x,a[p2].y]:=1;
        max:=max+1;
      end;
    end;
    if (a[p1].x-1>=0)and(table[a[p1].x,a[p1].y]and 4=0) then begin
      if t2[a[p1].x-1,a[p1].y]=0 then begin
        p2:=p2+1;
        a[p2].x:=a[p1].x-1;
        a[p2].y:=a[p1].y;
        t2[a[p2].x,a[p2].y]:=1;
        max:=max+1;
      end;
    end;
    if (a[p1].y+1<=101)and(table[a[p1].x,a[p1].y]and 2=0) then begin
      if t2[a[p1].x,a[p1].y+1]=0 then begin
        p2:=p2+1;
        a[p2].x:=a[p1].x;
        a[p2].y:=a[p1].y+1;
        t2[a[p2].x,a[p2].y]:=1;
        max:=max+1;
      end;
    end;
    if (a[p1].y-1>=0)and(table[a[p1].x,a[p1].y]and 8=0) then begin
      if t2[a[p1].x,a[p1].y-1]=0 then begin
        p2:=p2+1;
        a[p2].x:=a[p1].x;
        a[p2].y:=a[p1].y-1;
        t2[a[p2].x,a[p2].y]:=1;
        max:=max+1;
      end;
    end;
  end;
end;
begin
  fillchar(table,sizeof(table),0);
  fillchar(t2,sizeof(t2),0);
  assign(input,'fence.in');
  assign(output,'fence.out');
  reset(input);
  rewrite(output);
  readln(x,y,z);
  x:=x+1;
  y:=y+1;
  for i:=1 to z do
  begin
    read(f);
    readln(l);
    if f='N' then
    begin
      for j:=y to y+l-1 do
      begin
        table[j,x]:=table[j,x]or 8;
        table[j,x-1]:=table[j,x-1]or 2;
      end;
      y:=y+l;
    end;
    if f='S' then
    begin
      for j:=y downto y-l+1 do
      begin
        table[j-1,x]:=table[j-1,x]or 8;
        table[j-1,x-1]:=table[j-1,x-1]or 2;
       end;
      y:=y-l;
    end;
    if f='E' then
    begin
      for j:=x to x+l-1 do
      begin
        table[y,j]:=table[y,j]or 4;
        table[y-1,j]:=table[y-1,j]or 1;
      end;
      x:=x+l;
    end;
    if f='W' then
    begin
      for j:=x downto x-l+1 do
      begin
        table[y,j-1]:=table[y,j-1]or 4;
        table[y-1,j-1]:=table[y-1,j-1]or 1;
      end;
      x:=x-l;
    end;
  end;
  max:=0;
  for i:=0 to 101 do
    if t2[i,0]=0 then floodfill(i,0);
  for i:=0 to 101 do
    if t2[i,101]=0 then floodfill(i,101);
  for i:=1 to 100 do
    if t2[0,i]=0 then floodfill(0,i);
  for i:=1 to 100 do
    if t2[101,i]=0 then floodfill(101,i);
  writeln(10404-max);
  close(input);
  close(output);
end.