#P9572. 「NnOI R2-T4」Colorful Days♪

「NnOI R2-T4」Colorful Days♪

Problem Description

The following definitions are given:

  1. Define ABAB as the array obtained by concatenating array AA followed by array BB.
  2. Define A0={}A^{0}=\{\} (i.e., the empty array). For i=1,2,3,i=1,2,3,\cdots, define Ai=Ai1AA^{i}=A^{i-1}A.
  3. Define LCS(A,B)\operatorname{LCS}(A,B) as the length of the Longest Common Subsequence of arrays AA and BB.

Now you are given an array SS of length nn and an array TT of length mm. All numbers in the arrays are positive integers.

You need to find the smallest non-negative integer kk such that LCS(Sk,T)\operatorname{LCS}(S^k,T) is maximized.

The problem setter is very kind: if you cannot minimize kk, you can still get partial points.

Input Format

The first line contains four integers n,m,c1,c2n, m, c_1, c_2. The last two integers are output parameters, either 00 or 11.

The second line contains nn positive integers, representing array SS.

The third line contains mm positive integers, representing array TT.

Output Format

Output two integers c1LCS(Sk,T)c_1 \cdot \operatorname{LCS}(S^k,T) and c2kc_2 \cdot k.

3 4 1 1
23 34 53
53 25 23 34
3 2
9 10 1 1
15 12 26 21 26 21 23 12 23
26 11 21 15 16 15 12 23 17 12
7 3

Hint

[Sample 1 Explanation]

When k=2k = 2, $S^k = \text{\{23 34 \textcolor{red}{53 23 34} 53\}}$, where the red part is a longest common subsequence of SkS^k and TT.

[Constraints]

Note: This problem uses bundled testdata.

For 100%100\% of the testdata, it is guaranteed that 1n,m,Si,Ti1061 \le n, m, S_i, T_i \le 10^6, and c1,c2{0,1}c_1, c_2 \in \{0,1\}.

$$\def\r{\cr\hline} \def\None{\text{None}} \def\arraystretch{1.5} \begin{array}{c|c|c} \textbf{Subtask} & \textbf{Sp. Constraints} & \textbf{Score}\r \textsf1& c_1=c_2=0 & 2 \r \textsf2& n \le 10^3,m \le 10^2 & 8 \r \textsf3& n \le 10^4,m \le 10^3 & 15 \r \textsf4& c_2=0 & 15 \r \textsf5& n,m \le 10^5,S_i,T_i \le 26 & 20 \r \textsf6& 无特殊限制 & 40 \r \end{array}$$

The newly added hack test points after the contest will be included in subtask 7.

Problem Source

Item Person
idea Chuanjiang Mowang
data
check Sudohry
solution Chuanjiang Mowang

Translated by ChatGPT 5