Source: jige series stories-perfect formation II
Question: Chinese
Train of Thought: When the manacher algorithm expands to both sides, add judgment to ensure non-strict decline.
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 100110; int A [maxn <1]; int B [maxn <1]; int DP [maxn <1]; int manacher (INT N) {int maxlen = 0, ID, ANS = 0; for (INT I = 1; I <n; I ++) {If (maxlen> I) DP [I] = min (DP [ID * 2-I], maxlen-I); elsedp [I] = 1; int flag = 0, x = 1; if (a [I]! = 1) {flag = 1; X = A [I];} while (A [I + dp [I] = A [I-DP [I]) {if (a [I + dp [I] = 1) DP [I] ++; else {If (! Flag) {x = A [I + dp [I]; DP [I] ++; flag = 1 ;} else {if (a [I + dp [I]> X) break; X = A [I + dp [I]; DP [I] ++ ;}}} if (DP [I] + I> maxlen) {id = I; maxlen = DP [I] + I;} If (ANS <DP [I]) ans = DP [I];} return ans-1;} int main () {int t; scanf ("% d", & T); While (t --) {int N; scanf ("% d", & N); A [0] =-1; A [1] = 1; for (INT I = 1; I <= N; I ++) {scanf ("% d", & A [I <1]); A [I <1 | 1] = 1 ;} N = N * 2 + 2; A [n] = 2; printf ("% d \ n", manacher (n);} return 0 ;}