成功完成3连T!   嗯没错,三道TLE简直爽到不行,于是滚去看是不是模版出问题了..拿了3份其他P党的模版扔上去,嗯继续TLE...蒟蒻表示无能为力了...

思路像论文里面说的,依旧二分长度然后分组...然后记录下每个字符的最大和最小值去判断是否满足全部成立...完事...写起来其实蛮简单的...

const maxn=;
var
h,sum,rank,x,y,sa,c,lx,rx,col:array[..maxn] of longint;
n,k,maxlen,t,q:longint;
s:ansistring;
function max(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end;
function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end;
procedure swap(var x,y:longint); var tmp:longint; begin tmp:=x;x:=y;y:=tmp; end; procedure make;
var p,i,j,tot:longint;
begin
while p<n do
begin
fillchar(c,sizeof(c),);
for i:= to n-p do y[i]:=rank[i+p];
for i:= n-p+ to n do y[i]:=;
for i:= to n do inc(c[y[i]]);
for i:= to n do inc(c[i],c[i-]);
for i:= to n do
begin
sa[c[y[i]]]:=i;
dec(c[y[i]]);
end;
fillchar(c,sizeof(c),);
for i:= to n do x[i]:=rank[i];
for i:= to n do inc(c[x[i]]);
for i:= to n do inc(c[i],c[i-]);
for i:= n downto do
begin
y[sa[i]]:=c[x[sa[i]]];
dec(c[x[sa[i]]]);
end;
for i:= to n do sa[y[i]]:=i;
tot:=;
rank[sa[]]:=;
for i:= to n do
begin
if (x[sa[i]]<>x[sa[i-]]) or (x[sa[i]+p]<>x[sa[i-]+p]) then inc(tot);
rank[sa[i]]:=tot;
end;
if tot=n then break;
p:=p<<;
end;
for i:= to n do sa[rank[i]]:=i;
h[]:=; p:=;
for i:= to n do
begin
p:=max(p-,);
if rank[i]= then continue;
j:=sa[rank[i]-];
while (j+p<=n) and (i+p<=n) and (s[i+p]=s[j+p]) do inc(p);
h[rank[i]]:=p;
end;
end; procedure init;
var i,j,tot,p,m:longint;
s1:ansistring;
begin
readln(k);
readln(s);
for i:= to length(s) do col[i]:=;
maxlen:=length(s);
for i:= to k do
begin
readln(s1);
maxlen:=max(length(s1),maxlen);
s:=s+'#';
for j:= length(s)+ to length(s)+length(s1) do col[j]:=i;
s:=s+s1;
end;
n:=length(s);
fillchar(c,sizeof(c),);
for i:= to n do x[i]:=ord(s[i]);
for i:= to n do inc(c[x[i]]);
for i:= to do inc(c[i],c[i-]);
for i:= to n do
begin
sa[c[x[i]]]:=i;
dec(c[x[i]]);
end;
tot:=;
rank[sa[]]:=;
for i:= to n do
begin
if x[sa[i]]<>x[sa[i-]] then inc(tot);
rank[sa[i]]:=tot;
end;
make;
end; function check(len:longint):boolean;
var i,j,t,cnt:longint;
begin
for i:= to n do
begin
if h[i]<len then
begin
fillchar(lx,sizeof(lx),$7f);
fillchar(rx,sizeof(rx),);
lx[col[sa[i]]]:=sa[i];
rx[col[sa[i]]]:=sa[i];
end
else
begin
t:=col[sa[i]];
lx[t]:=min(lx[t],sa[i]);
rx[t]:=max(rx[t],sa[i]);
cnt:=;
for j:= to k do if rx[j]-lx[j]+>=len then inc(cnt);
if cnt=k then exit(true);
end;
end;
exit(false);
end; procedure solve;
var l,r,mid,ans:longint;
begin
l:=; r:=maxlen; ans:=;
while l<=r do
begin
mid:=(l+r)>>;
if check(mid) then
begin
ans:=mid;
l:=mid+;
end
else r:=mid-;
end;
writeln(ans);
end; Begin
readln(t);
for q:= to t do
begin
init;
solve;
end;
End.

最新文章

  1. distribution 中一直在运行 waitfor delay @strdelaytime 语句
  2. 从头到尾彻底理解KMP
  3. 当Sublime Text 2 遇到 EOFError: EOF when reading a line
  4. 在JAVA中ArrayList如何保证线程安全
  5. 2015年第14本(英文第10本):The A.B.C. Murders (A.B.C谋杀案)
  6. hdu 3183 贪心
  7. 使用Symfony 2在三小时内开发一个寻人平台
  8. hdu----(1466)计算直线的交点数(dp)
  9. vue.js插件使用(02) vue-router
  10. 安卓app开发方式之webApp
  11. mysql远程连接缓慢的问题
  12. 码云分布式之 Brzo 服务器
  13. iOS中使用图片作为颜色的背景图
  14. doc 窗口操作图
  15. LeetCode OJ 292.Nim Gam148. Sort List
  16. Vxworks驱动程序的结构
  17. 深入浅出Git教程(转载)
  18. 单点登录实现原理(SSO)
  19. Express中间件,看这篇文章就够了(#^.^#)
  20. help2man: can&#39;t get `--help&#39; info from automake-1.15 Try `--no-discard-stderr&#39; if option outputs to stderr Makefile:3687: recipe for target &#39;doc/automake-1.15.1&#39; failed

热门文章

  1. LeetCode46. Permutations
  2. BDC备忘
  3. 《JSON笔记之三》---postman中传入json串
  4. spring cloud 学习之服务消费者(Feign)
  5. Linux-日期时间相关命令
  6. oracle中序列,同义词的创建
  7. 【c学习-5】
  8. 动态代理和AOP
  9. PHP 微信公众号之客服完整讲解
  10. PHP时间日期操作增减(date strtotime) 加一天 加一月