比赛 | 20101117 | 评测结果 | TTTETETTEA |
---|---|---|---|
题目名称 | 拯救 | 最终得分 | 10 |
用户昵称 | 苏轼 | 运行时间 | 0.000 s |
代码语言 | Pascal | 内存使用 | 0.00 MiB |
提交时间 | 2010-11-17 11:16:13 | ||
- program savey(input,output);
- type
- re=record
- deep,n:longint;
- end;
- var
- n,i,len,dp,rec:longint;
- ch:char;
- boo:array[0..16777216]of boolean;
- q:array[1..1000000]of re;
- function expand(a:re):boolean;
- var
- i,t:longint;
- begin
- t:=a.n xor (1 shl (n-1));
- if t=0 then
- exit(true);
- if (t<16777216) and not(boo[t]) then
- begin
- inc(len);
- boo[t]:=true;
- q[len].deep:=a.deep+1;
- q[len].n:=t;
- end;
- for i:=n-1 downto 1 do
- if a.n shr i=1 then
- begin
- t:=a.n xor (1 shl (i-1));
- if t=0 then
- exit(true);
- if (t<16777216) and not(boo[t]) then
- begin
- inc(len);
- boo[t]:=true;
- q[len].deep:=a.deep+1;
- q[len].n:=t;
- end;
- end
- else if a.n shr i>1 then
- break;
- exit(false);
- end;
- begin
- assign(input,'savey.in');
- reset(input);
- assign(output,'savey.out');
- rewrite(output);
- readln(n);
- for i:=1 to n do
- begin
- read(ch);
- rec:=rec shl 1;
- if ch='1' then
- rec:=rec+1;
- read(ch);
- end;
- if rec=0 then
- begin
- writeln(0);
- close(input);
- close(output);
- halt;
- end;
- q[1].n:=rec;
- q[1].deep:=0;
- if (rec<16777216) then
- boo[rec]:=true;
- i:=1;
- dp:=0;
- len:=1;
- repeat
- while q[i].deep=dp do
- begin
- if expand(q[i]) then
- begin
- writeln(dp+1);
- close(input);
- close(output);
- halt;
- end;
- inc(i);
- end;
- inc(dp);
- until 1=2;
- end.