标签:就是 max input color des clu 超过 mes return
C/C++:
1 #include <map> 2 #include <queue> 3 #include <cmath> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <climits> 9 #include <iostream> 10 #include <algorithm> 11 #define INF 0x3f3f3f3f 12 using namespace std; 13 const int my_max = 3e5; 14 15 char my_str[my_max], my_temp[my_max]; 16 int my_ans[my_max], len1, len2; 17 18 void manacher() 19 { 20 int id = 0, mx = 0; 21 for (int i = 2; i < len2; ++ i) 22 { 23 if (mx > i) my_ans[i] = min(mx-i, my_ans[id*2 - i]); 24 else my_ans[i] = 1; 25 while (my_temp[i - my_ans[i]] == my_temp[i + my_ans[i]]) ++ my_ans[i]; 26 if (my_ans[i] + i > mx) 27 { 28 mx = my_ans[i] + i; 29 id = i; 30 } 31 } 32 } 33 34 int main() 35 { 36 while (~scanf("%s", my_str)) 37 { 38 len1 = strlen(my_str); 39 my_temp[0] = ‘$‘; 40 my_temp[1] = ‘#‘; 41 for (int i = 0, j = 2; i < len1; ++ i, j += 2) 42 { 43 my_temp[j] = my_str[i]; 44 my_temp[j + 1] = ‘#‘; 45 } 46 len2 = (len1 << 1) + 2; 47 my_temp[len2] = ‘*‘; 48 49 manacher(); 50 int temp = 0; 51 for (int i = 2; i < len2; ++ i) 52 if (temp < my_ans[i]) 53 temp = my_ans[i]; 54 55 printf("%d\n", temp - 1); 56 } 57 58 return 0; 59 }
标签:就是 max input color des clu 超过 mes return
原文地址:https://www.cnblogs.com/GetcharZp/p/9506523.html