QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 512 MB Puntuación total: 100

#13095. 电视节目游戏

Estadísticas

以电视节目闻名的 Dajuda 先生偶尔会为观众提供一个有趣的游戏,并赠送一些礼物作为奖品。他本周建议的游戏可以解释如下。

游戏开始时,舞台上的 $k (> 3)$ 盏灯都是熄灭的。为方便起见,灯的编号从 $1$ 到 $k$。每盏灯都有颜色,要么是红色,要么是蓝色。然而,在灯亮起之前,无法确定灯的颜色。游戏参与者被要求随机选择三盏灯并猜测它们的颜色。然后,每位参与者提交一张纸,上面记录了所选灯的预测颜色,并交给游戏主持人 Dajuda 先生。当所有的灯都亮起时,每位参与者检查有多少预测颜色与灯的实际颜色相符。如果两个或更多的颜色相符,他/她将获得一份精美的礼物作为奖品。

Dajuda 先生今天准备了一份特别的礼物。也就是说,在审阅了从游戏参与者那里收到的所有纸条后,他试图调整每盏灯的颜色,以便尽可能让每位参与者都能获得奖品。给定关于上述预测颜色的信息,编写一个程序,确定是否可以调整所有灯的颜色,使得所有参与者都能获得奖品。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $k$ 和 $n$ ($3 < k \le 5,000$, $1 \le n \le 10,000$),其中 $k$ 是灯的数量,$n$ 是游戏参与者的数量。接下来的 $n$ 行,每行包含三对 $(l, c)$,其中 $l$ 是他/她选择的灯的编号,$c$ 是一个字符,即 B(代表蓝色)或 R(代表红色),表示他/她对该灯颜色的猜测。$l$ 和 $c$ 之间有一个空格,每对 $(l, c)$ 之间也由一个空格隔开,如以下样例所示。

输出格式

程序将结果写入标准输出。如果可以调整所有颜色使得每位参与者都能获得奖品,则在一行中打印 $k$ 个字符。第 $i$ 个字符(B 代表蓝色,R 代表红色)表示第 $i$ 盏灯的颜色。如果不可能,则打印 -1。如果存在多个答案,你可以打印其中任何一个。

样例

样例输入 1

7 5
3 R 5 R 6 B
1 B 2 B 3 R
4 R 5 B 6 B
5 R 6 B 7 B
1 R 2 R 4 R

样例输出 1

BRRRBBB

样例输入 2

5 6
1 B 3 R 4 B
2 B 3 R 4 R
1 B 2 R 3 R
3 R 4 B 5 B
3 B 4 B 5 B
1 R 2 R 4 R

样例输出 2

-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.