考试竟然写错了manacher!太耻辱了!所以赶快又敲了一遍模板!!一定不能错了aaaa
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char a[11000005], M[22000010]; int max_r[22000010], ans; void manacher ( ) { int len = strlen ( a ); M[0] = '@'; M[1] = '#'; for ( int i = 0; i < len; i ++ ) { M[i*2+2] = a[i]; M[i*2+3] = '#'; } M[len*2+2] = '$'; int center = 0, mx = 0; for ( int i = 1; i <= len * 2 + 2; i ++ ) { if ( mx > i ) max_r[i] = min ( mx - i, max_r[center * 2 - i] ); else max_r[i] = 1; while ( M[i + max_r[i]] == M[i - max_r[i]] ) max_r[i] ++; if ( mx < i + max_r[i] ) { mx = i + max_r[i]; center = i; } ans = max ( ans, max_r[i] - 1 ); } } int main ( ) { scanf ( "%s", a ); manacher ( ); printf ( "%d", ans ); return 0; }