#P4324. [JSOI2016] 扭动的回文串
[JSOI2016] 扭动的回文串
Description
JYY has two strings and , both of length .
A "twisted string" is formed by concatenating the substring of from the -th character to the -th character and the substring of from the -th character to the -th character.
For example, if and , then the twisted string .
JYY defines a "twisted palindrome" as one of the following:
- A palindrome in ;
- A palindrome in ;
- Or a twisted string that is a palindrome.
Now JYY wants to find the longest twisted palindrome.
Input Format
The first line contains a positive integer . The second line contains a string of length consisting of uppercase letters. The third line contains a string of length consisting of uppercase letters.
Output Format
Output a single integer on the first line, the length of the longest twisted palindrome.
5
ABCDE
BAECB
5
Hint
Sample explanation:
The twisted palindrome in the best solution is shown below (characters not in the palindrome are marked with .):
.BC..
..ECB
Constraints: For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号