标签:manacher std str col names can == href %s
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 11000005; 4 int n, len, ans; 5 int r[maxn*2]; 6 char tmp[maxn], s[maxn*2]; 7 8 void init() { 9 scanf("%s", tmp+1); 10 n = strlen(tmp+1); 11 s[0] = ‘%‘; 12 for(int i = 1; i <= n; i++) { 13 s[++len] = ‘#‘; 14 s[++len] = tmp[i]; 15 } 16 s[++len] = ‘#‘, s[len+1] = ‘$‘; 17 return; 18 } 19 void manacher() { 20 int mx = 0, mid = 0; 21 for (int i = 1; i <= len; i++) { 22 if (i <= mx) r[i] = min(r[(mid*2)-i],mx-i); 23 while (s[i+r[i]+1] == s[i-r[i]-1]) ++r[i]; 24 if (r[i]+i > mx) mx = i+r[i], mid = i; 25 if (r[i] > ans) ans = r[i]; 26 } 27 return; 28 } 29 int main() { 30 init(); 31 manacher(); 32 printf("%d\n",ans); 33 return 0; 34 }
标签:manacher std str col names can == href %s
原文地址:https://www.cnblogs.com/wstong/p/11708042.html