#P10089. [ROIR 2022] 回文数组 (Day 1)
[ROIR 2022] 回文数组 (Day 1)
Background
Translated from ROIR 2022 D1T4。
There are two arrays of natural numbers, and 。
For each array, randomly remove a possibly empty prefix and a possibly empty suffix so that the remaining parts have the same length. Denote the resulting arrays by and , and their length is . Then, add the corresponding elements of these two arrays, and denote the resulting array by 。
For example, suppose $n = 5,A = [4, 3, 3, 2, 1],m = 6,B = [4, 1, 5, 1, 3, 2]$. Remove the first and the last elements from array , and remove the first three elements from array , obtaining . The sum of their corresponding elements is 。
Suppose . Remove the first two elements and the last element from array , and remove the first and the last elements from array , obtaining . The sum of their corresponding elements is 。
Problem Description
Find the maximum length such that it is possible to obtain a palindromic array 。
Input Format
The first line contains two integers and , representing the number of elements in the first array and the second array, respectively ()。
The second line contains integers , representing array ()。
The third line contains integers , representing array ()。
Output Format
Output one integer, the maximum possible length of a palindromic array that can be obtained。
5 6
4 3 3 2 1
4 1 5 1 3 2
3
Hint
This problem uses bundled testdata。
| Subtask | Score | Special Property |
|---|---|---|
| All numbers in are equal | ||
| None |
For all testdata, , , 。
Translated by ChatGPT 5