记录编号 7809 评测结果 AAAAAAAATTTTTTTATTTT
题目名称 奥术能量环流 最终得分 45
用户昵称 GravatarAchilles 是否通过 未通过
代码语言 Pascal 运行时间 12.923 s
提交时间 2008-11-11 20:09:50 内存使用 95.51 MiB
显示代码纯文本
program arcane;
var
  table:array[1..10000,1..10000]of 0..1;
  hx,hxt,hx2:array[1..10000]of 0..2;
  n,m,i,j,t,max,maxt:longint;
procedure max1(num:longint);
var
  i:integer;
begin
  for i:=1 to m*n do
  begin
    if (table[num,i]=1)and(hx[i]=0)and(hxt[i]=0) then begin
      hxt[i]:=1;
      max1(i);
    end;
  end;
end;
procedure max2(num:longint);
var
  i:integer;
begin
  for i:=1 to m*n do
  begin
    if (table[i,num]=1)and(hx[i]=0)and(hx2[i]=0) then begin
      hxt[i]:=hxt[i]+1;
      hx2[i]:=1;
      max2(i);
    end;
  end;
end;
begin
  fillchar(table,sizeof(table),0);
  fillchar(hx,sizeof(hx),0);
  assign(input,'arcane.in');
  assign(output,'arcane.out');
  reset(input);
  rewrite(output);
  readln(n,m);
  for i:=1 to n do
  begin
    for j:=1 to m do
    begin
      read(t);
      if (t and 8<>0)and(i-2>=0) then
        table[(i-1)*m+j,(i-2)*m+j]:=1;
      if (t and 4<>0)and(i*m+j<=n*m) then
        table[(i-1)*m+j,i*m+j]:=1;
      if (t and 2<>0)and(j-1>0) then
        table[(i-1)*m+j,(i-1)*m+j-1]:=1;
      if (t and 1<>0)and(j+1<=m) then
        table[(i-1)*m+j,(i-1)*m+j+1]:=1;
    end;
    readln;
  end;
  max:=0;
  for i:=1 to n*m do
  begin
    if hx[i]=0 then begin
      fillchar(hxt,sizeof(hxt),0);
      fillchar(hx2,sizeof(hx2),0);
      hxt[i]:=2;
      hx2[i]:=1;
      max1(i);
      max2(i);
      maxt:=0;
      for j:=1 to n*m do
      begin
        if hxt[j]=2 then begin
          hx[j]:=1;
          maxt:=maxt+1;
        end;
      end;
      if maxt>1 then max:=max+1;
    end;
  end;
  writeln(max);
  close(input);
  close(output);
end.