Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛帮忙看一下,老是wrong answerconst q=131131; p=29; var s,s1:ansistring; i,j,n,m,min,max,mid,r,kind:longint; hash:array[0..q]of ansistring; ch:array['a'..'z']of longint; cc:char; function ha(x:longint;s:ansistring):boolean; begin while hash[x]<>'' do begin if hash[x]=s then exit(false); x:=(x+1)mod q; end; if kind=1 then hash[x]:=s; exit(true); end; function ok(x:longint):boolean; var i,l,pp:longint; ss:ansistring; begin fillchar(hash,sizeof(hash),0); r:=1; for i:=2 to x do r:=r*p mod q; pp:=10000*q; l:=0; kind:=1; for i:=1 to x do l:=(l*p+ch[s[i]])mod q; ss:=copy(s,1,x); ha(l,ss); for i:=x+1 to n do begin delete(ss,1,1); ss:=ss+s[i]; l:=(((l-r*ch[s[i-x]]+pp)mod q)*p+ch[s[i]])mod q; ha(l,ss); end; l:=0; kind:=2; for i:=1 to x do l:=(l*p+ch[s1[i]])mod q; ss:=copy(s1,1,x); if not ha(l,ss) then exit(true); for i:=x+1 to m do begin delete(ss,1,1); ss:=ss+s1[i]; l:=(((l-r*ch[s1[i-x]]+pp)mod q)*p+ch[s1[i]])mod q; if not ha(l,ss) then exit(true); end; exit(false); end; begin readln(s);n:=length(s); readln(s1);m:=length(s1); min:=1; for cc:='a' to 'z' do ch[cc]:=ord(cc)-96; if n<m then max:=n else max:=m; while min<max do begin mid:=(min+max+1)shr 1; if ok(mid) then min:=mid else max:=mid-1; end; writeln(min); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator