比赛 20101224 评测结果 ETEEEEETEE
题目名称 激光电话 最终得分 0
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-12-24 20:57:04
显示代码纯文本
program lphone;
var
  a:array[0..100,0..100] of char;
  b:array[0..100,0..100] of longint;
  q:array[0..10000,0..2] of longint;
  n,m,t,h,t1,i,j,ans:longint;


function max(a,b:longint):longint;
begin
  if a>b
    then max:=a
    else max:=b;
end;

begin
  assign(input,'lphone.in');
  reset(input);
  assign(output,'lphone.out');
  rewrite(output);
  readln(m,n);
  t:=0;
  h:=0;
  for i:=1 to n do
  begin
    for j:=1 to m do
    begin
      read(a[i,j]);
      if a[i,j]='C' then
      begin
        inc(t);
        q[t,1]:=i;
        q[t,2]:=j;
        b[i,j]:=t;
      end;
    end;
    readln;
  end;
  repeat
    t1:=t;
    while h<t1 do
    begin
      ans:=ans+1;
      h:=h+1;

      i:=q[h,1];
      j:=q[h,2];
      while (i-1>0) and (a[i-1,j]='.') do
      begin
        i:=i-1;
        if b[i,j]>0 then
        begin
          if b[i,j]+b[i+1,j]=3 then
          begin
            if b[i+1,j]=1
              then writeln(max(0,ans*2-1-2))
              else writeln(max(0,ans*2-2));
            close(input);
            close(output);
            halt;
          end;
        end
        else
        begin
          b[i,j]:=b[i+1,j];
          int(t);
          q[t,1]:=i;
          q[t,2]:=j;
        end;
      end;

      i:=q[h,1];
      j:=q[h,2];
      while (i+1<n) and (a[i+1,j]='.') do
      begin
        i:=i+1;
        if b[i,j]>0 then
        begin
          if b[i,j]+b[i-1,j]=3 then
          begin
            if b[i-1,j]=1
              then writeln(max(0,ans*2-1-2))
              else writeln(max(0,ans*2-2));
            close(input);
            close(output);
            halt;
          end;
        end
        else
        begin
          b[i,j]:=b[i-1,j];
          int(t);
          q[t,1]:=i;
          q[t,2]:=j;
        end;
      end;

      i:=q[h,1];
      j:=q[h,2];
      while (j+1<n) and (a[i,j+1]='.') do
      begin
        j:=j+1;
        if b[i,j]>0 then
        begin
          if b[i,j]+b[i,j-1]=3 then
          begin
            if b[i,j-1]=1
              then writeln(max(0,ans*2-1-2))
              else writeln(max(0,ans*2-2));
            close(input);
            close(output);
            halt;
          end;
        end
        else
        begin
          b[i,j]:=b[i,j-1];
          int(t);
          q[t,1]:=i;
          q[t,2]:=j;
        end;
      end;

      i:=q[h,1];
      j:=q[h,2];
      while (j-1<n) and (a[i,j-1]='.') do
      begin
        j:=j-1;
        if b[i,j]>0 then
        begin
          if b[i,j]+b[i,j+1]=3 then
          begin
            if b[i,j+1]=1
              then writeln(max(0,ans*2-1-2))
              else writeln(max(0,ans*2-2));
            close(input);
            close(output);
            halt;
          end;
        end
        else
        begin
          b[i,j]:=b[i,j+1];
          int(t);
          q[t,1]:=i;
          q[t,2]:=j;
        end;
      end;
    end;
  until false;

  close(input);
  close(output);
end.