记录编号 67747 评测结果 AAAAAAAAAAAAAAAA
题目名称 [POI 1999] 位图 最终得分 100
用户昵称 GravatarTerryLam 是否通过 通过
代码语言 Pascal 运行时间 0.046 s
提交时间 2013-08-14 16:29:47 内存使用 0.63 MiB
显示代码纯文本
var
  a:array[0..183,0..183] of char;
  b:array[0..183,0..183] of longint;
  s1,s2:array[1..40000] of longint;
  n,m,i,j,t,p:longint;
begin
  assign(input,'bit.in');
  reset(input);
  readln(n,m);
  for i:=0 to n+1 do
    for j:=0 to m+1 do
      b[i,j]:=100000;
  t:=0;
  p:=0; 
  for i:=1 to n do
    begin
      for j:=1 to m do
        begin
          read(a[i,j]);
          if a[i,j]='1' then
            begin
              b[i,j]:=0;
              inc(t);
              s1[t]:=i;
              s2[t]:=j;
            end;
        end;
      readln;
    end;
  close(input);
  while p<t do
    begin
      inc(p);
      if (b[s1[p],s2[p]]+1<b[s1[p]-1,s2[p]]) and (s1[p]-1>0) then
        begin
          inc(t);
          s1[t]:=s1[p]-1;
          s2[t]:=s2[p];
          b[s1[p]-1,s2[p]]:=b[s1[p],s2[p]]+1;
        end;
      if (b[s1[p],s2[p]]+1<b[s1[p]+1,s2[p]]) and (s1[p]+1<n+1) then
        begin
          inc(t);
          s1[t]:=s1[p]+1;
          s2[t]:=s2[p];
          b[s1[p]+1,s2[p]]:=b[s1[p],s2[p]]+1;
        end;
      if (b[s1[p],s2[p]]+1<b[s1[p],s2[p]-1]) and (s2[p]-1>0) then
        begin
          inc(t);
          s1[t]:=s1[p];
          s2[t]:=s2[p]-1;
          b[s1[p],s2[p]-1]:=b[s1[p],s2[p]]+1;
        end;
      if (b[s1[p],s2[p]]+1<b[s1[p],s2[p]+1]) and (s2[p]-1<m+1) then
        begin
          inc(t);
          s1[t]:=s1[p];
          s2[t]:=s2[p]+1;
          b[s1[p],s2[p]+1]:=b[s1[p],s2[p]]+1;
        end;
    end;
  assign(output,'bit.out');
  rewrite(output);
  for i:=1 to n do
    begin
      for j:=1 to m-1 do write(b[i,j],' ');
      writeln(b[i,m]);
    end;
  close(output);
end.