Solution:
We need to find the longest palindrome suffix of S.
- compute the Z function for reverse(S)$S
- find the smallest i<n such that i+Z[i] = n
- append reverse(S[1,…,i-1]) to the end of S.
Solution:
We need to find the longest palindrome suffix of S.
Solution:
The hardest thing here is to prove that this procedure is correct.
Solution:
int res = 0; for(int i=0; i<n; i++) if(C[i]-S[i] <= 0 && B[i]+(S[n]-S[i]) <= 0) res++; return res;