영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
Given two arrays of integers, find their longest common subsequence.
A subsequence is a sequence of array elements from left to right that can contain gaps. A common subsequence is a subsequence that appears in both arrays.
Input
The first line has two integers n and m: the sizes of the arrays.
The second line has n integers a_1,a_2,…,a_n: the contents of the first array.
The third line has m integers b_1,b_2,…,b_m: the contents of the second array.
Output
First print the length of the longest common subsequence.
After that, print an example of such a sequence. If there are several solutions, you can print any of them.
Constraints
- 1 ≤ n,m ≤ 1000
- 1 ≤ a_i, b_i ≤ 10^9
예제
예제 1
8 6 3 1 3 2 7 4 8 2 6 5 1 2 3 4
3 1 2 4