标签:
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 }
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9666 Accepted Submission(s): 3355
标签:
原文地址:http://www.cnblogs.com/Tunix/p/4397698.html