Logo
(追記) (追記ここまで)

20617번 - Longest Common Subsequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB969913.846%

문제

Chiaki has two sequences $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. She would like to find their longest common subsequence $c_1,c_2,\ldots,c_k$ such that $c_1 \le c_2 \le \ldots \le c_k$.

입력

There are multiple test cases. The first line of input contains an integer $T,ドル indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ (1ドル \le n, m \le 10^6$): the lengths of two sequences.

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ (1ドル \le a_i \le 3$).

The third line contains $m$ integers $b_1,b_2,\ldots,b_m$ (1ドル \le b_i \le 3$).

It is guaranteed that the sum of $\max\{n,m\}$ in all test cases does not exceed 10ドル^6$.

출력

For each test case, output a single integer $k$: the length of the longest common subsequence $c_1,c_2,\ldots,c_k$ such that $c_1 \le c_2 \le \ldots \le c_k$.

제한

예제 입력 1

3
3 3
1 2 3
1 2 3
3 3
1 1 1
1 1 2
3 3
1 3 2
1 2 3

예제 출력 1

3
2
2

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 4: Xi Lin Contest 6 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /