比赛 20101117 评测结果 TTTTWTTTWA
题目名称 拯救 最终得分 10
用户昵称 Des. 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 10:35:45
显示代码纯文本
program savey;
var q:array[1..1000000]of dword;
    d:array[1..1000000]of longint;
    t,k,m,n,i,j:longint;
    an:dword;
begin
assign(input,'savey.in');
reset(input);
assign(output,'savey.out');
rewrite(output);
readln(n);
for t:=1 to n do
  begin
    read(i);
    if i=1 then
      an:=an+(1 shl(t-1));
  end;
i:=0;
j:=1;
q[1]:=an;
repeat
  inc(i);
  an:=q[i]xor 1;
  if an=0 then
    begin
      writeln(d[i]+1);
      close(output);
      halt;
    end;
  for t:=1 to j do
    if q[t]=an then
      break;
  if q[t]<>an then
    begin
      inc(j);
      q[j]:=an;
      d[j]:=d[i]+1;
    end;
  for t:=1 to 30 do
    if (q[i] shr (t-1))and 1=1 then
      break;
  an:=q[i] xor(1 shl (t));
  if an=0 then
    begin
      writeln(d[i]+1);
      close(output);
      halt;
    end;
  for t:=1 to j do
    if q[t]=an then
      break;
  if q[t]<>an then
    begin
      inc(j);
      q[j]:=an;
      d[j]:=d[i]+1;
    end;
until i=j;
end.