No.1328 alligachi-problem
Problem Statement
There are $N$ balls numbered from $1$ to $N$, and ball $i$ is painted in color $C_i$ (the color of a ball is either red or blue). We want to arrange these balls in a row from left to right in any order so that the following condition is satisfied.
- For every integer $i\ (1 \le i \le N)$, there are exactly $Y_i$ balls of color $X_i$ to the left of ball $i$ (not counting that ball itself).
Determine whether an arrangement satisfying this condition exists, and if one exists, show one.
Input
$N$ $C_1\ X_1\ Y_1$ $C_2\ X_2\ Y_2$ $\vdots$ $C_N\ X_N\ Y_N$
- All numerical values in the input are integers.
- $1 \le N \le 2 \times 10^5$
- $C_i, X_i$ are each
RorB, representing red and blue respectively. - $0 \le Y_i < N$
Output
If an arrangement satisfying the condition exists, print Yes on the first line, and on the second line print the integer sequence $A$ of length $N$, where $A_i=$ (the number of the ball placed $i$-th from the left), separated by spaces, followed by a newline at the end. If there are multiple arrangements satisfying the condition, you may print any of them. Note that $1 \le A_i \le N$ and $A_i \neq A_j\ (i \neq j)$ must both be satisfied.
Yes $A_1\ A_2\ \dots\ A_N$
If no such arrangement exists, print No on one line, followed by a newline at the end.
No
(Added 2020/12/25 7:34) Note that extra trailing whitespace will result in WA.
Sample
Sample 1
Input
5 B R 1 R R 1 B B 2 R R 0 B B 0
Output
Yes 4 5 1 2 3
There may be multiple solutions. For example, in this case, $(5,4,1,2,3)$ and others are also correct.
Sample 2
Input
4 R R 0 R R 0 B R 1 B B 1
Output
No
There may be no solution.
Sample 3
Input
10 B B 0 R R 2 R B 3 R B 1 R B 3 R B 3 R R 1 B B 2 R R 0 B R 4
Output
Yes 9 7 2 1 4 10 8 3 5 6
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
沙耶花