Hieroglyphs

시간 제한1초메모리 제한1024 MB

요약
두 수열 A와 B가 주어질 때, 모든 공통 부분 수열을 부분 수열로 포함하는 보편 공통 부분 수열을 구하거나 존재하지 않음을 판정한다.
난이도

어려움10점 중 9점

유형
그리디, 배열
정답자
아직 제출이 없습니다

문제

A team of researchers is studying the similarities between sequences of hieroglyphs. They represent each hieroglyph with a non-negative integer. To perform their study, they use the following concepts about sequences.

For a fixed sequence AA, a sequence SS is called a subsequence of AA if and only if SS can be obtained by removing some elements (possibly none) from AA.

The table below shows some examples of subsequences of a sequence A=\[3,2,1,2]A = \[3, 2, 1, 2].

SubsequenceHow it can be obtained from AA
\[3,2,1,2]\[3, 2, 1, 2]No elements are removed.
\[2,1,2]\[2, 1, 2]\[\enclosehorizontalstrike3,2,1,2]\[\enclose{horizontalstrike}{3}, 2, 1, 2]
\[3,2,2]\[3, 2, 2]\[3,2,\enclosehorizontalstrike1,2]\[3, 2, \enclose{horizontalstrike}{1}, 2]
\[3,2]\[3, 2]\[3,\enclosehorizontalstrike2,\enclosehorizontalstrike1,2]\[3, \enclose{horizontalstrike}{2}, \enclose{horizontalstrike}{1}, 2] or \[3,2,\enclosehorizontalstrike1,\enclosehorizontalstrike2]\[3, 2, \enclose{horizontalstrike}{1}, \enclose{horizontalstrike}{2}]
\[3]\[3]\[3,\enclosehorizontalstrike2,\enclosehorizontalstrike1,\enclosehorizontalstrike2]\[3, \enclose{horizontalstrike}{2}, \enclose{horizontalstrike}{1}, \enclose{horizontalstrike}{2}]
\[]\[ ]\[\enclosehorizontalstrike3,\enclosehorizontalstrike2,\enclosehorizontalstrike1,\enclosehorizontalstrike2]\[\enclose{horizontalstrike}{3}, \enclose{horizontalstrike}{2}, \enclose{horizontalstrike}{1}, \enclose{horizontalstrike}{2}]

On the other hand, \[3,3]\[3, 3] or \[1,3]\[1, 3] are not subsequences of AA.

Consider two sequences of hieroglyphs, AA and BB. A sequence SS is called a common subsequence of AA and BB if and only if SS is a subsequence of both AA and BB. Moreover, we say that a sequence UU is a universal common subsequence of AA and BB if and only if the following two conditions are met:

  • UU is a common subsequence of AA and BB.
  • Every common subsequence of AA and BB is also a subsequence of UU.

It can be shown that any two sequences AA and BB have at most one universal common subsequence.

The researchers have found two sequences of hieroglyphs AA and BB. Sequence AA consists of NN hieroglyphs and sequence BB consists of MM hieroglyphs. Help the researchers compute a universal common subsequence of sequences AA and BB, or determine that such a sequence does not exist.

제한

  • 1≤N≤100,0001 ≤ N ≤ 100\\, 000
  • 1≤M≤100,0001 ≤ M ≤ 100\\, 000
  • 0≤A\[i]≤200,0000 ≤ A\[i] ≤ 200\\, 000 for each ii such that 0≤i<N0 ≤ i < N
  • 0≤B\[j]≤200,0000 ≤ B\[j] ≤ 200\\, 000 for each jj such that 0≤j<M0 ≤ j < M

예제

이 문제는 공개된 예제가 없습니다.