The official name of Korea Digital Media High School is too long
Time limit1sMemory limit1024 MB
Split string S into a prefix and suffix to maximize min(|A|, |B|) minus the length of their longest common substring.
- Level
Medium6 of 10
- Topics
- String, Dynamic programming, String matching
- Solved
- No attempts yet
Problem
The official name of DIMIGO, Korea Digital Media High School, is too long. The student council plans to split the school into a liberal arts school and a science school to shorten the names. The liberal arts school will have the Digital Content and E-Business departments, and the science school will have the Web Programming and Hacking Defense departments. The student council must name the two new schools.
The student council decided to split the original name into a contiguous front part and the remaining back part to keep the school's identity. For example, KoreaDigitalMediaHighSchool can be split into the front part KoreaDigital and the back part MediaHighSchool. The front part or the back part may be an empty string.
The two departments are rivals, so the student council wants the two names to differ as much as possible. To judge this objectively, it uses a mismatch value. Let A and B be the two strings from splitting the school name. The mismatch value is . For a string S, is the length of S, and is the smaller of x and y.
LCS(A, B) is the length of the longest string that is a substring of both A and B, where letter case matters. For example, the longest common substring of ABCD and ABDF is ABD, so LCS is 3. A substring is made by removing zero or more characters from the original string while keeping the order. For example, ABC and BD are substrings of ABCD, but BDC, EAB, and abc are not.
Find the maximum possible mismatch value that splits Korea Digital Media High School well.
Input
The first line contains the school name S, a string of uppercase and lowercase English letters.
Output
Print the maximum mismatch value on the first line.