萌新刚学字符串求助
查看原帖
萌新刚学字符串求助
347944
Vigna楼主2020/6/26 00:42

也不算刚学吧,以前学过KMP和RE自动机

请问为什么这份代码只有10分啊/fad

后面4个点RE又是怎么回事啊/youl

#include<iostream>
#include<cstring>
#include<cstdio>
const int M=1e6+5;
char s[M];
int n,m,b[129],x[M],y[M],suff[M];
void suffix_array(){
    register int i,k,m=1<<7,num;
    for(i=1;i<=n;++i)++b[x[i]=s[i]];
    for(i=1;i<=m;++i)b[i]+=b[i-1];
    for(i=n;i;--i)suff[b[x[i]]--]=i;
    for(k=1;k<=n;k<<=1){
        num=0;
        for(i=n-k+1;i<=n;++i)y[++num]=i;
        for(i=1;i<=n;++i)if(suff[i]>k)y[++num]=suff[i]-k;
        for(i=1;i<=m;++i)b[i]=0;
        for(i=1;i<=n;++i)++b[x[i]];
        for(i=1;i<=m;++i)b[i]+=b[i-1];
        for(i=n;i;--i)suff[b[x[y[i]]]--]=y[i],y[i]=0;
        std::swap(x,y);
        x[suff[num=1]]=1;
        for(i=2;i<=n;++i){
            if(y[suff[i]]!=y[suff[i-1]]||y[suff[i]+k]!=y[suff[i-1]+k])++num;
            x[suff[i]]=num;
        }
        if(num==n)return;
        m=num;
    }
}
signed main(){
    scanf("%s",s+1);
    n=std::strlen(s+1);
    suffix_array();
    for(int i=1;i<=n;++i)printf("%d ",suff[i]);
}
2020/6/26 00:42
加载中...