Logo caxx_jiangyucheng的博客

博客

魔导大陆答案

2023-06-13 20:18:59 By caxx_jiangyucheng

1星题目不用说太简单就不写了

#include <bits/stdc++.h>
#define int long long
#define CIO std::ios::sync_with_stdio(false)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define nep(i, r, l) for (int i = r; i >= l; i--)
using namespace std;
const int N=2e6+5;
char s[N];
int nxt[N];
int ma=-1;
void next(){
    int i=0,j=-1;
    nxt[0]=-1;
    while (i<strlen(s)){
        if (j==-1||s[i]==s[j]){
            i++;j++;
            nxt[i]=j;
            ma=max(j,ma);
        }
        else{
            j=nxt[j];
        }
    }
}
void work(){
    cin>>s;
    next();
    cout<<ma;
}
signed main(){
    CIO;
    work();
    return 0;
}

评论

暂无评论