比赛 20120706 评测结果 AAEEEETTTT
题目名称 解密 最终得分 20
用户昵称 isabella 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-06 11:51:43
显示代码纯文本
var
 tree:array[1..1000000]of ansistring;
 a,num,b,po:array[1..1000000]of longint;
 min,max:array[0..1000000]of longint;
 s,c:ansistring;
 i,j,p,tot,n,m,k,temp,tt,ii:longint;

 function make(c:ansistring):longint;
  var i:longint;
  begin
   i:=1;
   while tree[i]<>'' do
    begin
      if c=tree[i] then exit(num[i]);
      if c>tree[i] then i:=i*2+1 else i:=i*2;
    end;
   inc(tot);
   tree[i]:=c;num[i]:=tot;
   exit(tot);
  end;

begin
assign(input,'kriptogram.in');reset(input);
assign(output,'kriptogram.out');rewrite(output);
 readln(s);tot:=0;
 p:=pos(' ',s);
 n:=0;
 min[0]:=maxlongint;max[0]:=0;
 while p<>0 do
  begin
   c:=copy(s,1,p-1);
   inc(n);a[n]:=make(c);
   if (a[n]<min[n-1])then min[n]:=a[n] else min[n]:=min[n-1];
   if (a[n]>max[n-1])then max[n]:=a[n] else max[n]:=max[n-1];
   delete(s,1,p);p:=pos(' ',s);
  end;

 fillchar(tree,sizeof(tree),0);
 fillchar(num,sizeof(num),0);
 readln(s);tot:=0;
 p:=pos(' ',s);
 m:=0;
 while p<>0 do
  begin
   c:=copy(s,1,p-1);
   inc(m);b[m]:=make(c);
   delete(s,1,p);p:=pos(' ',s);
  end;
 tt:=tot;

 for i:=1 to m do
  if a[i]<>b[i] then break;
 if (i=m)and(a[i]=b[i])then
  begin writeln(1);close(input);close(output);halt;end;

 for i:=2 to n+1-m do
  begin
   ii:=i+m-1;
   if tt>(max[ii]-min[ii]+1)then continue;
   fillchar(po,sizeof(po),0);
   tot:=0;
   for j:=i to ii do
    begin
     if po[a[j]]=0 then begin inc(tot);k:=tot;po[a[j]]:=tot;end
      else k:=po[a[j]];
     if k<>b[j-i+1]then break;
    end;
   if (j=i+m-1)and(k=b[m])then
    begin writeln(i);close(input);close(output);halt;end;
  end;
 close(input);close(output);
end.