比赛 |
20120706 |
评测结果 |
AWWWWWWWWW |
题目名称 |
解密 |
最终得分 |
10 |
用户昵称 |
zhangchi |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-06 09:39:07 |
显示代码纯文本
type
node=record
str:string[30];
num,next:longint;
end;
var
i,j,k,len,tot,nnum,mnum:longint;
ch:char;
s:string[30];
n,m:array[1..1000000] of longint;
hash:array[1..1000000] of longint;
link:array[1..1000000] of node;
fail:array[1..1000000] of longint;
fac:array[1..1000000] of longint;
fnum:array[1..1000000] of longint;
fac2:array[1..1000000] of longint;
fnum2:array[1..1000000] of longint;
function cherk:longint;
var
i,t,p:longint;
begin
t:=1;
for i:=1 to length(s) do
t:=(t*ord(s[i])) mod 999997;
p:=hash[t];
while p<>0 do
begin
if link[p].str=s then exit(link[p].num);
p:=link[p].next;
end;
inc(tot);
link[tot].next:=hash[t];
hash[t]:=tot;
link[tot].num:=tot;
link[tot].str:=s;
exit(tot);
end;
begin
assign(input,'kriptogram.in'); reset(input);
assign(output,'kriptogram.out'); rewrite(output);
fillchar(hash,sizeof(hash),0);
fillchar(link,sizeof(link),0);
tot:=0; s:='';
read(ch);
while ch<>'$' do
begin
if ch=' ' then
begin
inc(nnum);
n[nnum]:=cherk;
s:='';
read(ch);
continue;
end;
s:=s+ch;
read(ch);
end;
readln;
fillchar(hash,sizeof(hash),0);
fillchar(link,sizeof(link),0);
tot:=0;s:='';
read(ch);
while ch<>'$' do
begin
if ch=' ' then
begin
inc(mnum);
m[mnum]:=cherk;
s:='';
read(ch);
continue;
end;
s:=s+ch;
read(ch);
end;
readln;
j:=0;
fail[1]:=0;
for i:=2 to mnum do
begin
while (j>0)and(m[j+1]<>m[i]) do j:=fail[j];
if m[j+1]=m[i] then inc(j);
fail[i]:=j;
end;
j:=0;
for i:=1 to nnum do
begin
while (j>0)and(((fac[m[j+1]]<>n[i])and(fnum[m[j+1]]<>0))or((fac2[n[i]]<>m[j+1])and(fnum2[n[i]]<>0))) do
begin
for k:=fail[j]+1 to j-fail[j] do
begin
dec(fnum[m[k]]);
dec(fnum2[fac[m[k]]]);
end;
j:=fail[j];
end;
if (fac[m[j+1]]=n[i])or(fnum[m[j+1]]=0) then
begin
fac[m[j+1]]:=n[i];
inc(fnum[m[j+1]]);
fac2[n[i]]:=m[j+1];
inc(fnum2[n[i]]);
inc(j);
end;
if j=mnum then
begin
writeln(i-mnum+1);
close(input); close(output);
halt;
end;
end;
end.