CF1344F.Piet's Palette

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Piet Mondrian is an artist most famous for his minimalist works, consisting only of the four colors red, yellow, blue, and white. Most people attribute this to his style, but the truth is that his paint behaves in a very strange way where mixing two primary colors only produces another primary color!

A lesser known piece, entitled "Pretentious rectangles"

A sequence of primary colors (red, yellow, blue) is mixed as follows. While there are at least two colors, look at the first two. If they are distinct, replace them with the missing color. If they are the same, remove them from the sequence. In the end, if there is one color, that is the resulting color. Otherwise, if the sequence is empty, we say the resulting color is white. Here are two example mixings:

Piet has a color palette with cells numbered from 11 to nn. Each cell contains a primary color or is empty. Piet is very secretive, and will not share his palette with you, so you do not know what colors belong to each cell.

However, he did perform kk operations. There are four kinds of operations:

  1. In a mix operation, Piet chooses a subset of cells and mixes their colors together in some order. The order is not necessarily by increasing indexes. He records the resulting color. Empty cells are skipped over, having no effect on the mixing process. The mixing does not change the color values stored in the cells.
  2. In a RY operation, Piet chooses a subset of cells. Any red cells in this subset become yellow, and any yellow cells in this subset become red. Blue and empty cells remain unchanged.
  3. In a RB operation, Piet chooses a subset of cells. Any red cells in this subset become blue, and any blue cells in this subset become red. Yellow and empty cells remain unchanged.
  4. In a YB operation, Piet chooses a subset of cells. Any yellow cells in this subset become blue, and any blue cells in this subset become yellow. Red and empty cells remain unchanged.

Piet only tells you the list of operations he performs in chronological order, the indexes involved, and the resulting color of each mix operation. For each mix operation, you also know the order in which the cells are mixed. Given this information, determine the color of each cell in the initial palette. That is, you should find one possible state of the palette (before any operations were performed), or say that the described situation is impossible.

皮特·蒙德里安(Piet Mondrian)是一位以极简主义作品闻名的艺术家,其画作仅使用红、黄、蓝、白四种颜色。多数人将此归因于他的艺术风格;但事实是,他所用颜料的行为极为奇特——两种原色混合后仅能生成另一种原色!

一幅鲜为人知的作品,题为《矫饰的矩形》

对一个由原色(红、黄、蓝)构成的序列,按如下方式混合:只要序列中至少含有两个颜色,就考察前两个颜色。若二者不同,则将其替换为缺失的第三种原色;若二者相同,则将它们从序列中移除。最终,若序列中剩下一个颜色,则该颜色即为混合结果;若序列为空,则称混合结果为白色。以下是两次混合过程的示例:

皮特拥有一块调色板,其单元格编号从 11 到 nn。每个单元格中包含一种原色,或为空。皮特极为保密,不会向你透露调色板内容,因此你无法得知各单元格初始对应的颜色。

然而,他执行了 kk 次操作。操作共分四类:

  1. 混合操作(mix operation):皮特选择若干单元格,并以某种顺序混合其中的颜色。该顺序不一定按单元格编号升序排列。他记录下混合所得的颜色。空单元格被跳过,对混合过程无任何影响。混合操作不会改变各单元格中存储的颜色值。
  2. RY 操作:皮特选择若干单元格。该子集中所有红色单元格变为黄色,所有黄色单元格变为红色;蓝色与空单元格保持不变。
  3. RB 操作:皮特选择若干单元格。该子集中所有红色单元格变为蓝色,所有蓝色单元格变为红色;黄色与空单元格保持不变。
  4. YB 操作:皮特选择若干单元格。该子集中所有黄色单元格变为蓝色,所有蓝色单元格变为黄色;红色与空单元格保持不变。

皮特仅向你提供他按时间顺序执行的操作列表、每次操作涉及的单元格编号,以及每次混合操作的结果颜色。对于每次混合操作,你还知道参与混合的单元格顺序。根据这些信息,请确定调色板中每个单元格的初始颜色。即:请找出一种可能的初始调色板状态(即所有操作开始前的状态),或判定所述情形不可能实现。

输入格式

The first line contains two integers nn and kk (1≤n,k≤10001\le n,k\le 1000) — the number of cells in the palette and the number of operations, respectively.

The next kk lines describe the operations. The ii-th line begins with the name of the ii-th operation and an integer mm (1≤m≤n1\le m\le n) — the number of indexes involved. Then follow mm integers j1,…,jmj_1,\ldots,j_m (1≤ji≤n1\le j_i\le n) — the indexes of the operation. It is guaranteed that all jij_i are distinct within an operation. If it is a mix operation, the indexes are listed in the order the colors are mixed, and the line also ends with a character representing the resulting color: "R" for red, "Y" for yellow, "B" for blue, and "W" for white.

第一行包含两个整数 nn 和 kk(1≤n,k≤10001\le n,k\le 1000),分别表示调色板中的格子数量和操作次数。

接下来的 kk 行描述这些操作。第 ii 行以第 ii 个操作的名称和一个整数 mm(1≤m≤n1\le m\le n)开头,表示该操作涉及的索引个数;随后是 mm 个整数 j1,…,jmj_1,\ldots,j_m(1≤ji≤n1\le j_i\le n),即该操作所涉及的索引。保证同一操作中所有 jij_i 互不相同。若为混合(mix)操作,则这些索引按颜色混合的顺序列出,且该行末尾还包含一个字符,表示混合后得到的颜色:“R” 表示红色,“Y” 表示黄色,“B” 表示蓝色,“W” 表示白色。

输出格式

Output "YES" if a solution exists, or "NO" otherwise. You can print each character in any case (upper or lower).

If the answer is "YES", on the next line output a string of length nn, consisting of characters "R", "Y", "B", and ".", representing the paint colors in the nn cells of the initial palette (red, yellow, blue, and empty, respectively). If there are multiple solutions, print any. You can print each character in any case (upper or lower).

如果存在解,输出 "YES";否则输出 "NO"。每个字符可使用任意大小写(大写或小写)。

如果答案为 "YES",则在下一行输出一个长度为 nn 的字符串,该字符串由字符 "R"、"Y"、"B" 和 "." 组成,分别表示初始调色板中 nn 个格子的颜料颜色(红色、黄色、蓝色和空置)。若存在多个解,输出任意一个即可。每个字符可使用任意大小写(大写或小写)。

输入输出样例

  • 输入#1

    3 2
    mix 2 2 1 R
    mix 2 1 3 Y

    输出#1

    YES
    YB.
  • 输入#2

    2 3
    mix 1 2 Y
    RB 1 2
    mix 1 2 W

    输出#2

    NO
  • 输入#3

    1 3
    RY 1 1
    YB 1 1
    mix 1 1 B

    输出#3

    YES
    R
  • 输入#4

    3 8
    mix 2 1 2 R
    mix 2 1 3 Y
    RY 2 2 3
    RB 3 1 2 3
    YB 3 1 2 3
    mix 1 1 W
    mix 1 2 B
    mix 1 3 Y

    输出#4

    YES
    .RY

说明/提示

For the first test case, the answer "YB." is consistent with both mixings. The first mixing "BY" results in red, while the second mixing "Y" results in yellow (the empty cell is ignored). Other valid solutions include "BYR" and ".RY".

For the second test case, we can show that no solution exists.

For the third test case, the answer "R" is consistent with all operations. In the first two operations it changes to "Y", then "B". In the final operation, the mixing "B" results in blue.

For the fourth test case, the answer ".RY" is consistent with all operations. The first two mixings are "R" and "Y", resulting in red and yellow, respectively. During the next three operations, the palette changes to ".YR", then ".YB", then ".BY". The final three mixings agree with this palette.

对于第一个测试用例,答案“YB.”与两种混合操作均一致。第一次混合“BY”得到红色,而第二次混合“Y”得到黄色(空单元格被忽略)。其他合法解包括“BYR”和“.RY”。

对于第二个测试用例,可以证明不存在可行解。

对于第三个测试用例,答案“R”与所有操作均一致。在前两次操作中,它依次变为“Y”,然后变为“B”。在最后一次操作中,混合“B”得到蓝色。

对于第四个测试用例,答案“.RY”与所有操作均一致。前两次混合分别为“R”和“Y”,分别得到红色和黄色。接下来的三次操作中,调色板依次变为“.YR”、“.YB”和“.BY”。最后三次混合结果与该调色板一致。

输入解题思路,AI测评打分。不知道怎么写?

首页