记录编号 39043 评测结果 AAAAAAAAAA
题目名称 基因重组 最终得分 100
用户昵称 Gravatarczp 是否通过 通过
代码语言 Pascal 运行时间 0.314 s
提交时间 2012-07-03 17:30:08 内存使用 103.16 MiB
显示代码纯文本
const wl:array[1..12] of longint=(1,4,16,64,256,1024,4096,16384,65536,262144,1048576,4194304);
var
 hash:array[0..17000000] of longint;
 i,j,m,n,MB,x,x1,x2,nx,h,t,TX:longint;
 d:array[1..10000000] of longint;
 p:array['A'..'Z'] OF longint;
 ss:string;
function change(s:string):longint;
var i,l,o:longint;
begin
 l:=length(s);o:=0;
 for i:=l downto 1 do
  begin
   o:=o*4;
   o:=o+p[s[i]];
  end;
 change:=O;
end;
function get(v:longint):longint;
var i,j:longint;
begin
 get:=(x div wl[v]) mod 4;
end;
begin
 assign(input,'genea.in');reset(input);
 assign(output,'genea.out');rewrite(output);
 p['A']:=0;P['C']:=1;P['G']:=2;P['T']:=3;
 readln(n);
 readln(ss);
 d[1]:=change(ss);
 hash[d[1]]:=1;
 readln(ss);
 mb:=change(ss);
 h:=0;t:=1;
 repeat
  inc(h);
  x:=d[h];
     x1:=get(1);
     x2:=get(2);
     nx:=(x2-x1)*wl[1]+x;
     nx:=(x1-x2)*wl[2]+nx;
     if hash[nx]=0 then
        begin
         if nx=mb then begin writeln(hash[x]); close(input);close(output);halt;  end;
         inc(t);
         d[t]:=nx;
         hash[nx]:=hash[x]+1;
        end;
  x1:=get(1);
  tx:=x-x1;tx:=tx div 4;
  nx:=tx+wl[n]*x1;
  if hash[nx]=0 then
        begin
         if nx=mb then begin writeln(hash[x]); close(input);close(output);halt;  end;
         inc(t);
         d[t]:=nx;
         hash[nx]:=hash[x]+1;
        end;
 until h>=t;
 close(input);close(output);
end.