记录编号 191341 评测结果 AAAAAAAAAA
题目名称 [NOIP 2010冲刺十三]迷之阶梯 最终得分 100
用户昵称 Gravatarwaijsf 是否通过 通过
代码语言 Pascal 运行时间 0.003 s
提交时间 2015-10-07 09:48:02 内存使用 0.67 MiB
显示代码纯文本
program Project1;
  var
    n,i:longint;
    a,mi:array[0..200]of longint;
    f:array[1..200,0..200]of boolean;
    st:array[1..40400,1..3]of longint;
  procedure doi;
    var
      i,x,y,t,h,t1:longint;
      ne:int64;
    begin
      h:=1;
      t:=1;
      while (st[h,1]<>n)and(h<=t) do
      begin
      x:=st[h,1];
      y:=st[h,2];
      t1:=st[h,3];
      if f[x-1,y+1]
        then
          begin
            f[x-1,y+1]:=false;
            inc(t);
            st[t,1]:=x-1;
            st[t,2]:=y+1;
            st[t,3]:=t1+1;
          end;
      ne:=a[x];
      inc(ne,mi[y]);
      for i:=n downto x do
        if (a[i]<=ne)and f[i,0]
          then
            begin
              f[i,0]:=false;
              inc(t);
              st[t,1]:=i;
              st[t,2]:=0;
              st[t,3]:=t1+1;
            end;
        inc(h);
      end;
      if h>t
        then
          st[h,3]:=-1;
      writeln(st[h,3]);
    end;
  begin
    assign(input,'ladder.in');
    reset(input);
    assign(output,'ladder.out');
    rewrite(output);
    readln(n);
    mi[0]:=1;
    for i:=1 to n do
      begin
        read(a[i]);
        mi[i]:=mi[i-1]*2;
      end;
    fillchar(f,sizeof(f),true);
    f[1,0]:=false;
    st[1,1]:=1;
    st[1,2]:=0;
    st[1,3]:=0;
    doi;
    close(input);
    close(output);
  end.