#P13786. [eJOI 2022] LCS of Permutations
[eJOI 2022] LCS of Permutations
题目描述
For two sequences and , we define as the length of their longest common subsequence.
You are given 4 integers . Determine if there exist 3 permutations of integers from 1 to , such that:
If such permutations exist, find any such triple of permutations.
A permutation of integers from 1 to is a sequence of length such that all elements are distinct integers in the range . For example, is a permutation of integers from 1 to 5 while and are not.
A sequence is a subsequence of a sequence if can be obtained from by deletion of several (possibly, zero or all) elements. For example, is a subsequence of while is not.
The longest common subsequence of the sequences and is the longest sequence which is a subsequence of both and . For example, the longest common subsequence of the sequences and is since it is a subsequence of both sequences and is the longest among such subsequences. is the length of the longest common subsequence, which is 2 in the example above.
输入格式
The first line of the input contains a single integer () - the number of test cases. The description of the test cases follows.
The only line of each test case contains 5 integers (, ).
If , just determine if such permutations exist. If , you also have to find such a triple of permutations if it exists.
It's guaranteed that the sum of over all test cases doesn't exceed .
输出格式
For each test case, in the first line, output "YES", if such permutations exist, and "NO" otherwise. If , and such permutations exist, output three more lines:
In the first line output integers - the elements of the permutation .
In the second line output integers - the elements of the permutation .
In the third line output integers - the elements of the permutation .
If there are multiple triples, output any of them.
You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer).
8
1 1 1 1 1
4 2 3 4 1
6 4 5 5 1
7 1 2 3 1
1 1 1 1 0
4 2 3 4 0
6 4 5 5 0
7 1 2 3 0
YES
1
1
1
NO
YES
1 3 5 2 6 4
3 1 5 2 4 6
1 3 5 2 4 6
NO
YES
NO
YES
NO
提示
Note
In the first test case, is 1.
In the second test case, it can be shown that no such permutations exist.
In the third test case, one of the examples is , , . It's easy to see that:
- (one of the longest common subsequences is )
- (one of the longest common subsequences is )
- (one of the longest common subsequences is )
In the fourth test case, it can be shown that no such permutations exist.
Scoring
- (3 points):
- (8 points):
- (10 points):
- (17 points):
- (22 points):
- (40 points):