| ||||||||||
| 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 | |||||||||
哪位大神帮我看看——老是WA啊const maxn=200000 ;
var n,k,i,j,num,z,p,sum,ans:longint;
height,rank,sa,y,x,a:array[0..maxn]of longint;
procedure sort(l,r:longint);
var i,j,k,p,t:longint;
begin
i:=l;j:=r;k:=x[(i+j)>>1];p:=y[(i+j)>>1];
repeat
while (x[i]<k)or((x[i]=k)and(y[i]<p)) do inc(i);
while (x[j]>k)or((x[j]=k)and(y[j]>p)) do dec(j);
if i<=j then
begin
t:=x[i];x[i]:=x[j];x[j]:=t;
t:=y[i];y[i]:=y[j];y[j]:=t;
t:=sa[i];sa[i]:=sa[j];sa[j]:=t;
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
procedure make_height;
begin
z:=0;
//for i:=1 to n do write(a[i],' ');
for i:=1 to n do
begin
if rank[i]=1 then continue;
if z<=0 then z:=0 else dec(z);
while a[i+z]=a[sa[rank[i]-1]+z] do inc(z);
height[rank[i]]:=z;
end;
end;
procedure init;
begin
readln(n,k);
fillchar(a,sizeof(a),255);
p:=0;
for i:=1 to n do
begin
readln(a[i]);
rank[i]:=a[i];
if a[i]>p then p:=a[i];
end;
if p=0 then
begin
writeln(n);
halt;
end;
p:=1;
while p<=n-1 do
begin
for i:=1 to n do sa[i]:=i;
for i:=1 to n do x[i]:=rank[i];
for i:=1 to n do y[i]:=rank[i+p];
sort(1,n);
sum:=1;
rank[sa[1]]:=1;
for i:=2 to n do
begin
if (x[i]<>x[i-1])or(y[i]<>y[i-1]) then inc(sum);
rank[sa[i]]:=sum;
end;
if sum=n then break;
p:=p * 2;
end;
make_height;
end;
function max(x,y:longint):longint;
begin
if x<y then exit(y);
exit(x);
end;
procedure main;
begin
num:=1;
ans:=0;
for i:=2 to n do
begin
if height[i]>height[i-1] then
begin
inc(num);
if num>=k then ans:=max(ans,height[i-k+2]);
end
else num:=1;
end;
writeln(ans);
end;
begin
init;
main;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator