#P10089. [ROIR 2022] 回文数组 (Day 1)

[ROIR 2022] 回文数组 (Day 1)

Background

Translated from ROIR 2022 D1T4

There are two arrays of natural numbers, A=[a1,a2,,an]A = [a_1, a_2, \dots , a_n] and B=[b1,b2,,bm]B = [b_1, b_2, \dots , b_m]

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 AA' and BB', and their length is kk. Then, add the corresponding elements of these two arrays, and denote the resulting array by C=[c1,c2,,ck]C = [c_1, c_2, \dots , c_k]

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 AA, and remove the first three elements from array BB, obtaining A=[3,3,2],B=[1,3,2]A' = [3, 3, 2],B' = [1, 3, 2]. The sum of their corresponding elements is C=[4,6,4]C = [4, 6, 4]
Suppose n=7,A=[1,9,1,9,8,1,0],m=6,B=[1,1,4,5,1,4]n = 7,A = [1,9,1,9,8,1,0],m = 6,B = [1,1,4,5,1,4]. Remove the first two elements and the last element from array AA, and remove the first and the last elements from array BB, obtaining A=[1,9,8,1],B=[1,4,5,1]A' = [1,9,8,1],B' = [1,4,5,1]. The sum of their corresponding elements is C=[2,13,13,2]C = [2,13,13,2]

Problem Description

Find the maximum length kk such that it is possible to obtain a palindromic array CC

Input Format

The first line contains two integers nn and mm, representing the number of elements in the first array and the second array, respectively (1n,m1000001 \le n, m \le 100 000)。

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, representing array AA (1ai1001 \le a_i \le 100)。

The third line contains mm integers b1,b2,,bnb_1,b_2,\dots,b_n, representing array BB (1bi1001 \le b_i \le 100)。

Output Format

Output one integer, the maximum possible length kk 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
11 1313 n,m300n,m\le300
22 3333 All numbers in BB are equal
33 1616 n500,m105n\le500,m\le10^5
44 3838 None

For all testdata, 1n,m1000001 \le n, m \le 100 000, 1ai1001 \le a_i \le 100, 1bi1001 \le b_i \le 100

Translated by ChatGPT 5