记录编号 22207 评测结果 AAAAAAAAAA
题目名称 拯救 最终得分 100
用户昵称 Gravatarmaxiem 是否通过 通过
代码语言 Pascal 运行时间 0.136 s
提交时间 2010-11-17 17:35:10 内存使用 5.84 MiB
显示代码纯文本
program savey;
var
  data:array [1..1000] of byte;
  f:array [0..1,1..1000,0..1000] of integer;
  g:array [1..1000,0..1000] of integer;
  get,n,i,j:integer;
procedure add(op,go:integer);
var
  len,i:integer;
begin
  if g[go,0]>f[1,go,0] then len:=g[go,0] else len:=f[1,go,0];
  get:=1;
  for i:=1 to len do begin
    f[op,go+1,i]:=f[1,go,i]+g[go,i]+get;
    if f[op,go+1,i]>=10 then begin
      dec(f[op,go+1,i],10);
      get:=1;
    end
    else get:=0;
  end;
  if get=1 then begin
    f[op,go+1,len+1]:=1;
    f[op,go+1,0]:=len+1;
  end
  else f[op,go+1,0]:=len;
end;
procedure addg(num:integer);
var i:integer;
begin
  get:=1;
  for i:=1 to g[num-1,0] do begin
    g[num,i]:=g[num-1,i]*2+get;
    if g[num,i]>=10 then begin
      dec(g[num,i],10);
      get:=1;
    end
    else get:=0;
  end;
  if get=1 then begin
    g[num,g[num-1,0]+1]:=1;
    g[num,0]:=g[num-1,0]+1;
  end
  else g[num,0]:=g[num-1,0];
end;
begin
  assign (input,'savey.in');
  reset (input);
  readln (n);
  for i:=1 to n do read (data[i]);
  close (input);
  fillchar (f,sizeof(f),0);
  fillchar (g,sizeof(g),0);
  assign (output,'savey.out');
  rewrite (output);
  g[1,0]:=1;g[1,1]:=1;
  for i:=2 to n do addg(i);
  if data[1]=1 then begin
    f[0,1,1]:=1;
	f[1,1,1]:=0;
        f[0,1,0]:=1;
        f[1,1,0]:=1;
  end
  else begin
    f[0,1,1]:=0;
	f[1,1,1]:=1;
        f[0,1,0]:=1;
        f[1,1,0]:=1;
  end;
  for i:=2 to n do begin
    if data[i]=1 then begin
          add(0,i-1);
	  f[1,i]:=f[0,i-1];
	end
	else begin
	  f[0,i]:=f[0,i-1];
          add(1,i-1);
	end;
  end;
  for i:=f[0,n,0] downto 1 do write (f[0,n,i]);
  writeln;
  close (output);
end.