QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#8599. 彩色表格

統計

给定一个大小为 $n \times m$ 的表格 $a$,由字符“R”、“G”、“B”组成。 同时给定整数 $c$ ($2 \le c \le 3$) 和 $q$,其中 $c$ 是表格中可能出现的不同字符的数量。如果 $c=2$,则仅有字符“R”和“G”可用;如果 $c=3$,则字符“R”、“G”、“B”均可用。

你需要修改表格中不超过 $q$ 个元素的值,使得不存在任何一对相邻(有公共边)的单元格具有相同的值。注意,如果 $c=2$,则在修改表格单元格的值时禁止使用字符“B”。

题目保证在给定的限制条件下,存在一种修改不超过 $q$ 个表格元素的方法,使得不存在任何一对相邻的单元格具有相同的值。

注意,本题没有“无附加限制”的子任务。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 100$),分别表示表格 $a$ 的行数和列数。

第二行包含两个整数 $c$ ($2 \le c \le 3$) 和 $q$,分别表示可用字符的数量和允许修改的次数。

接下来的 $n$ 行,每行包含 $m$ 个字符,表示表格 $a$ 的元素。如果 $c=2$,则 $a_{ij} \in \{\text{'R'}, \text{'G'}\}$。如果 $c=3$,则 $a_{ij} \in \{\text{'R'}, \text{'G'}, \text{'B'}\}$。

输出格式

输出 $n$ 行,每行 $m$ 个字符,描述修改后的表格。 如果存在多个正确答案,输出其中任意一个即可。

子任务

  1. (7 分): $n = 1, c = 3, q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  2. (7 分): $n = 1, c = 2, q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  3. (3 分): $c = 3, q = n \cdot m$;
  4. (7 分): 表格 $a$ 的所有行相同,$a[1][j] \neq a[1][j + 1]$ (对于 $1 \le j < m$), $c = 3, q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  5. (7 分): 表格 $a$ 的所有行相同,$c = 3, q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  6. (13 分): $c = 3, q = \lfloor \frac{2 \cdot n \cdot m}{3} \rfloor$;
  7. (19 分): $c = 3, n \le 5, m \le 100, q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  8. (17 分): $c = 2, q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  9. (20 分): $c = 3, q = \lfloor \frac{n \cdot m}{2} \rfloor$.

样例

输入 1

3 3
3 4
RRR
RRR
RRR

输出 1

RGR
GRG
RGR

输入 2

3 2
2 3
RG
GG
GR

输出 2

RG
GR
RG

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.