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
The table below shows some examples of subsequences of a sequence
Subsequence | How it can be obtained from |
---|---|
[3, 2, 1, 2] | No elements are removed. |
[2, 1, 2] | [ |
[3, 2, 2] | [3, 2, |
[3, 2] | [3, |
[3] | [3, |
[ ] | [ |
On the other hand,
Consider two sequences of hieroglyphs,
is a common subsequence of and .- Every common subsequence of
and is also a subsequence of .
It can be shown that any two sequences
The researchers have found two sequences of hieroglyphs
Implementation details
You should implement the following procedure.
std::vector<int> ucs(std::vector<int> A, std::vector<int> B)
: array of length describing the first sequence. : array of length describing the second sequence.- If there exists a universal common subsequence of
and , the procedure should return an array containing this sequence. Otherwise, the procedure should return (an array of length , whose only element is ). - This procedure is called exactly once for each test case.
Constraints
for each such that for each such that
Subtasks
Subtask | Score | Additional Constraints |
---|---|---|
1 | ||
2 | For any integer |
|
3 | ||
4 | There exists a universal common subsequence of |
|
5 | ||
6 | No additional constraints. |
Examples
Example 1
Consider the following call.
ucs([0, 0, 1, 0, 1, 2], [2, 0, 1, 0, 2])
Here, the common subsequences of
Since
Example 2
Consider the following call.
ucs([0, 0, 2], [1, 1])
Here, the only common subsequence of
Example 3
Consider the following call.
ucs([0, 1, 0], [1, 0, 1])
Here, the common subsequences of
Sample Grader
Input format:
N M
A[0] A[1] ... A[N-1]
B[0] B[1] ... B[M-1]
Output format:
T
R[0] R[1] ... R[T-1]
Here, ucs
and
Attachment Package
The sample grader along with sample test cases are available here.
Comments