Isomorphic Inversion
Time limit1sMemory limit512 MB
Split a digit string into the largest number of contiguous pieces whose sequence of pieces reads the same forward and backward.
- Level
Hard8 of 10
- Topics
- Greedy, String matching, Two pointers, Hash map
- Solved
- No attempts yet
Problem
Let be a given string of up to digits. Find the maximal for which it is possible to partition into consecutive contiguous substrings such that the parts form a palindrome. More precisely, we say that strings form a palindrome if for all .
In the first sample case, we can split the string 652526 into 4 parts as 6|52|52|6, and these parts together form a palindrome. It turns out that it is impossible to split this input into more than 4 parts while still making sure the parts form a palindrome.
Input
- A nonempty string of up to digits.
Output
- Print the maximal value of on a single line.