标签:col 不能 manacher max ++ for cstring printf mil
考试竟然写错了manacher!太耻辱了!所以赶快又敲了一遍模板!!一定不能错了aaaa
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 6 char a[11000005], M[22000010]; 7 int max_r[22000010], ans; 8 9 void manacher ( ) { 10 int len = strlen ( a ); 11 M[0] = ‘@‘; M[1] = ‘#‘; 12 for ( int i = 0; i < len; i ++ ) { 13 M[i*2+2] = a[i]; 14 M[i*2+3] = ‘#‘; 15 } 16 M[len*2+2] = ‘$‘; 17 int center = 0, mx = 0; 18 for ( int i = 1; i <= len * 2 + 2; i ++ ) { 19 if ( mx > i ) max_r[i] = min ( mx - i, max_r[center * 2 - i] ); 20 else max_r[i] = 1; 21 while ( M[i + max_r[i]] == M[i - max_r[i]] ) max_r[i] ++; 22 if ( mx < i + max_r[i] ) { 23 mx = i + max_r[i]; center = i; 24 } 25 ans = max ( ans, max_r[i] - 1 ); 26 } 27 } 28 29 int main ( ) { 30 scanf ( "%s", a ); 31 manacher ( ); 32 printf ( "%d", ans ); 33 return 0; 34 }
标签:col 不能 manacher max ++ for cstring printf mil
原文地址:https://www.cnblogs.com/wans-caesar-02111007/p/9484187.html