No.1370 Substitution Kadomatsu Sequence
Definition
It has been handed down that a sequence $v = (a_1,a_2,a_3)$ consisting of 3 elements is a Kadomatsu sequence if $v$ satisfies the following conditions.
- $a_1,a_2,a_3$ are all distinct
- Among the 3 elements, $a_2$ is the largest or the smallest
Furthermore, when a sequence $w = (a_1,...,a_n)$ consisting of $n$ elements (where $3\le n$) is such that
any 3 consecutive elements taken from it form a Kadomatsu sequence,
$w$ is called a Kadomatsu sequence sequence.
Problem Statement
Determine whether there exists an assignment of $x_1, x_2, \ldots, x_M$ such that the sequence $x_{a_1}, x_{a_2}, \ldots, x_{a_N}$ is a Kadomatsu sequence sequence, and if one exists, output one such assignment.
Input
$N$ $M$ $a_1$ .. $a_N$
$3 \le N \le 10^5$
$1 \le M \le 10^5$
$1 \le a_i \le M$
All values in the input are integers.
Output
If no assignment satisfying the condition exists, output No.
If one exists, output Yes, and then output $x_1, x_2, \ldots, x_M$ separated by newlines or by single-byte spaces.
They must be integers satisfying the constraint $1 \le x_i \le 10^9$.
This problem uses a special judge. There are multiple solutions, and you may output any of them.
Sample
Sample 1
Input
4 3 1 2 3 1
Output
Yes 2 3 1
Assigning as in the output gives 2 3 1 2. This is a Kadomatsu sequence sequence.
Outputting 4 3 5 is also OK.
Sample 2
Input
5 3 1 3 3 3 1
Output
No
There may be unused variables.
Sample 3
Input
6 3 1 2 3 1 2 3
Output
No
Sample 4
Input
9 9 9 8 7 6 5 4 3 2 1
Output
Yes 1 3 2 4 1 3 2 5 4
The sample output is merely one example. There are multiple solutions.
Sample 5
Input
3 2 2 1 2
Output
No
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
QCFium