Hieroglyphs
Time limit1sMemory limit1024 MB
Find the universal common subsequence of two integer sequences A and B, or report that none exists.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Array
- Solved
- No attempts yet
Problem
A team of researchers is studying the similarities between sequences of hieroglyphs. Each hieroglyph is represented by a non-negative integer.
For a fixed sequence , a sequence is a subsequence of if can be obtained by removing some elements (possibly none) from .
For example, and are not subsequences of .
For two sequences and , a sequence is a common subsequence of and if is a subsequence of both. A sequence is a universal common subsequence of and if both of the following hold:
- is a common subsequence of and .
- Every common subsequence of and is also a subsequence of .
Any two sequences and have at most one universal common subsequence.
The researchers have two sequences and . Sequence has hieroglyphs and sequence has hieroglyphs. Compute a universal common subsequence of and , or determine that none exists.
Constraints
- for each such that
- for each such that