Manacher模板题……

 1 //HDOJ 3068
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<iostream>
 6 #include<algorithm>
 7 #define rep(i,n) for(int i=0;i<n;++i)
 8 #define F(i,j,n) for(int i=j;i<=n;++i)
 9 #define D(i,j,n) for(int i=j;i>=n;--i)
10 using namespace std;
11 typedef long long LL;
12 inline int getint(){
13     int r=1,v=0; char ch=getchar();
14     for(;!isdigit(ch);ch=getchar()) if(ch=='-')r=-1;
15     for(; isdigit(ch);ch=getchar()) v=v*10+ch-'0';
16     return r*v;
17 }
18 const int N=1e5+10,INF=~0u>>2;
19 /*******************template********************/
20 char b[N];
21 int p[N<<1],a[N<<1];
22 int main(){
23 #ifndef ONLINE_JUDGE 
24     freopen("3068.in","r",stdin);
25 //    freopen("3068.out","w",stdout);
26 #endif
27     int n,id,mx,ans;
28     while(scanf("%s",b)!=EOF){
29         n=strlen(b);
30         memset(p,0,sizeof p);
31         F(i,1,n) a[i<<1]=b[i-1];
32         n=n<<1|1;
33         id=mx=ans=0;
34         F(i,1,n){
35             if (mx>i) p[i]=min(p[2*id-i],mx-i);
36             while(i-p[i]-1>0 && i+p[i]+1<=n && a[i-p[i]-1]==a[i+p[i]+1]) p[i]++;
37             if (p[i]+i>mx) mx=p[i]+i,id=i;
38             if (p[i]>ans) ans=p[i];
39         }
40         printf("%d\n",ans);
41     }
42     return 0;
43 }
View Code

相关文章:

  • 2021-09-13
  • 2022-02-10
  • 2021-10-08
  • 2021-12-03
  • 2022-01-28
  • 2022-01-08
  • 2022-12-23
  • 2021-04-08
猜你喜欢
  • 2021-10-21
  • 2022-01-02
  • 2022-02-07
  • 2022-12-23
相关资源
相似解决方案