比赛 NOIP2008集训模拟4 评测结果 AAAWAWWWWAWWA
题目名称 潜入辛迪加 最终得分 46
用户昵称 francis 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 11:18:29
显示代码纯文本
program syndicata;
const
fin='syndicate.in';
fou='syndicate.out';
g:array[1..4,1..2]of longint=((-1,0),(0,1),(1,0),(0,-1));
var
a:array[1..50,1..50]of longint;
d:array[1..300000,1..3]of longint;
b:array[0..35,1..50,1..50]of boolean;
deep,yy,xx,p,k,x,y,n,m,i,j:longint;
f1,f2:text;

procedure print;
begin
write(f2,deep);
close(f1); close(f2);
halt;
end;

procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
read(f1,n,m);
for i:=1 to n do
for j:=1 to n do
begin
 read(f1,a[i,j]);
 if a[i,j]=-2 then
               begin
                    for k:=1 to 4 do
                     begin
                      xx:=i+g[k,1]; yy:=j+g[k,2];
                      if (xx>0)and(xx<=n)and(yy>0)and(yy<=n) then
                         a[xx,yy]:=-3;
                     end;
              end;

end;
k:=0;
d[1,1]:=1; d[1,2]:=1; d[1,3]:=k;
b[k,1,1]:=true;
x:=1; y:=1; p:=1;
if n=1 then print;
end;

procedure main;
var
i,j,xx,yy,kk:longint;
begin
while x<=y do
begin
inc(deep);
for i:=x to y do
for j:=1 to 4 do
 begin
  xx:=d[i,1]+g[j,1]; yy:=d[i,2]+g[j,2];
  if (xx>0)and(xx<=n)and(yy>0)and(yy<=n)and(a[xx,yy]>=0)and(a[xx,yy]-m<=d[i,3])
   then
    begin
     if (a[xx,yy]>0)and(a[xx,yy]<=m)and(a[xx,yy]>d[i,3]) then kk:=a[xx,yy]
                                                         else kk:=d[i,3];
     if b[kk,xx,yy]=false then
       begin
        if (xx=n)and(yy=n) then print;
        b[kk,xx,yy]:=true;
        inc(p);
        d[p,1]:=xx; d[p,2]:=yy; d[p,3]:=kk;
       end;
    end;
 end;
x:=y+1; y:=p;
end;
end;

begin
init;
main;
end.