問題一覧 > 通常問題

No.1328 alligachi-problem

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 43
作問者 : first_vil / テスター : 沙耶花
お気に入りにしたユーザー ProblemId : 5572 / 自分の提出
問題文最終更新日: 2021-01-08 23:50:49
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2020 (順位表) の他の問題:

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 R or B, 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もしくは右上の雲マークをクリックしてアカウントを作成してください。