#P12556. [UOI 2024] Colorful Table

[UOI 2024] Colorful Table

题目描述

You are given a table aa of size n×mn \times m, consisting of symbols R\tt{R}, G\tt{G}, B\tt{B}.

Also, given are integers cc (2c32 \leq c \leq 3) and qq, where cc is the number of different symbols that can appear in the table. If cc equals 22, only the symbols R\tt{R} and G\tt{G} are available; if cc equals 33, the symbols R\tt{R}, G\tt{G}, B\tt{B} are available.

You need to change the values of at most qq elements of the table so that there are no pairs of neighboring cells with the same value. Note that if c=2c=2, using the symbol B\tt{B} when changing the values of the table cells is prohibited.

It is guaranteed that under the given constraints, there is a way to change the values of at most qq elements of the table so that there are no pairs of neighboring cells with the same value.

Note that there are no additional constraints in the problem.

输入格式

The first line contains two integers nn and mm (1n,m1001 \leq n, m \leq 100) --- the number of rows and columns of the table aa respectively.

The second line contains two integers cc (2c32 \leq c \leq 3) and qq, representing the number of available symbols and the number of allowed changes in the table, respectively.

The next nn lines contain mm symbols each --- the elements of the table aa. If c=2c=2, then aija_{ij} \in {R,G}\{\tt{R}, \tt{G}\}. If c=3c=3, then aija_{ij} \in {R,G,B}\{\tt{R}, \tt{G}, \tt{B}\}.

输出格式

Output nn lines of mm symbols each, describing the table after the changes.

If there are multiple correct answers, any of them is allowed.

3 3
3 4
RRR
RRR
RRR
RGR
GRG
RGR

3 2
2 3
RG
GG
GR
RG
GR
RG

提示

Scoring

  • (77 points): $n = 1,\ c = 3,\ q = \lfloor \frac{n \cdot m}{2} \rfloor $;
  • (77 points): $n = 1,\ c = 2,\ q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  • (33 points): c=3, q=nmc = 3,\ q = n \cdot m;
  • (77 points): all rows of table aa are the same, a[1][j]a[1][j+1]a[1][j] \neq a[1][j+1] (for 1j<m1 \leq j < m), c=3c = 3, q=nm2q = \lfloor \frac{n \cdot m}{2} \rfloor;
  • (77 points): all rows of table aa are the same, c=3c = 3, q=nm2q = \lfloor \frac{n \cdot m}{2} \rfloor;
  • (1313 points): $c = 3,\ q = \lfloor \frac{2 \cdot n \cdot m}{3} \rfloor $;
  • (1919 points): $c = 3,\ n \leq 5,\ m \leq 100,\ q = \lfloor \frac{n \cdot m}{2} \rfloor$;
  • (1717 points): c=2, q=nm2c = 2,\ q = \lfloor \frac{n \cdot m}{2} \rfloor;
  • (2020 points): c=3, q=nm2c = 3,\ q = \lfloor \frac{n \cdot m}{2} \rfloor.