問題一覧 > 通常問題

No.2042 RGB Caps

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 134
作問者 : 👑 箱星 / テスター : 👑 hitonanode 👑 Kazun
お気に入りにしたユーザー ProblemId : 7149 / 自分の提出
問題文最終更新日: 2022-08-20 00:23:01
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
yukicoder contest 357 (順位表) の他の問題:

Problem Statement

$N$ students stand in a line, each wearing a cap that is red, green, or blue. The students are numbered $1,2,\ldots,N$ from the front of the line.

You have obtained $K$ testimonies. The $i$-th testimony is as follows:

  • Among the caps of the $1$-st through $A_i$-th students, one of the most frequently appearing colors is $c_i$.

Here, $c_i$ is one of R, G, B, representing red, green, and blue, respectively. Also, $A_i\ne A_j$ holds if $i\ne j$.

Based on these testimonies, find $1$ possible way the students could be wearing their caps. However, if the testimonies are contradictory, report that.

Constraints

  • $1\le K\le N\le 10^5$
  • $1\le A_i\le N$
  • $A_i\ne A_j$ if $i\ne j$
  • $c_i$ is one of R, G, B
  • $N,K,A_i$ are integers

Input

$N$ $K$
$A_1$ $c_1$
$\vdots$
$A_K$ $c_K$

Output

If the testimonies are contradictory, output $-1$.

Otherwise, output $N$ characters on $1$ line. The $i$-th character should be R if the $i$-th student is wearing a red cap, G if wearing a green cap, and B if wearing a blue cap.

If there are multiple answers, you may output any of them.

Sample

Sample 1
Input
5 3
3 G
5 B
1 R
Output
RGGBB
  • Regarding the $1$-st testimony: among the $1$-st through $3$-rd students, $1$ student has a red cap and $2$ students have a green cap, so the most frequently appearing color is green.
  • Regarding the $2$-nd testimony: among the $1$-st through $5$-th students, $1$ student has a red cap, $2$ students have a green cap, and $2$ students have a blue cap, so the most frequently appearing colors are green and blue.
  • Regarding the $3$-rd testimony: the $1$-st student has a red cap, so the most frequently appearing color is red.

Therefore, this output satisfies the conditions.

Sample 2
Input
12 5
2 R
3 R
5 R
7 R
11 B
Output
RRRBRBRBBBBB

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。