标签:cout sign man mes pac span stack unsigned ons
小小模板,是个好东西呀!!
#include <cstdio> #include <cmath> #include <deque> #include <stack> #include <queue> #include <cmath> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define ll long long #define ull unsigned long long const int Maxn=22000001; const int inf=2147483647; int n,m,hw[Maxn]; char s[Maxn],a[Maxn]; void change() { s[0]=s[1]=‘#‘; for(int i=0; i<n; i++) { s[i*2+2]=a[i]; s[i*2+3]=‘#‘; } n=n*2+2; s[n]=0; return; } int main() { cin>>a; n=strlen(a); change(); int r=0,mid=0; for(int i=1; i<n; i++) { if(i<r) hw[i]=min(hw[mid-(i-mid)],hw[mid]-(i-mid)); else hw[i]=1; while(s[i+hw[i]]==s[i-hw[i]]) ++hw[i]; if(i+hw[i]>r) { r=hw[i]+i; mid=i; } } int ans=1; for(int i=0; i<n; i++) ans=max(ans,hw[i]); cout<<ans-1<<endl; return 0; }
标签:cout sign man mes pac span stack unsigned ons
原文地址:https://www.cnblogs.com/Shen-Yu/p/9880431.html