#P14689. [ICPC 2025 Yokohama R] ICPC Board

[ICPC 2025 Yokohama R] ICPC Board

题目描述

As an archaeologist, you have discovered a rectangular wooden board in the ruins of an ancient city. The board is divided into a grid, and each grid cell appears to have been engraved originally with one of the letters 'C', 'I', and 'P'. However, due to decay over time, some of the letters are now indistinguishable.

During your investigation, you made the following hypothesis: any square of 2×22 \times 2 cells on the board originally had two 'C's, one 'I', and one 'P'.

You now want to check whether this hypothesis is consistent with the discovered board. If it is, show one possibility of the original arrangement of the letters that aligns with the hypothesis.

输入格式

The input contains one or more test cases. The first line of the input contains an integer tt (1t5001 \le t \le 500), which is the number of test cases. The descriptions of the tt test cases follow, each in the following format.

n mn\ m c1,1 c1,2  c1,mc_{1,1}\ c_{1,2}\ \cdots\ c_{1,m} c2,1 c2,2  c2,mc_{2,1}\ c_{2,2}\ \cdots\ c_{2,m} \vdots cn,1 cn,2  cn,mc_{n,1}\ c_{n,2}\ \cdots\ c_{n,m}

The first line of a test case contains two integers nn and mm (2n10002 \le n \le 1000, 2m10002 \le m \le 1000). They represent the number of rows and columns of the board, respectively. The next nn lines, each containing mm characters, describe the discovered board. The jj-th character of the ii-th line, ci,jc_{i,j}, is one of 'C', 'I', 'P', and '?'. If ci,jc_{i,j} is 'C', 'I', or 'P', the cell in row ii and column jj is identifiable as having that letter. If ci,jc_{i,j} is '?', the letter in that cell is indistinguishable.

The sum of nn's over all the test cases does not exceed 1000. The same applies to mm.

输出格式

For each test case, if the hypothesis is not consistent with the discovered board, output nono in a single line. Otherwise, output yesyes in the first line, followed by nn lines representing one possibility of the original arrangement of the letters that aligns with the hypothesis. Each of these nn lines should contain mm characters. The jj-th character of the ii-th line should be the letter in the cell in row ii and column jj. If there are multiple possible arrangements, you may output any of them.

3
5 7
I?I?I?I
?P?P?P?
I?I?I?I
?P?P?P?
I?I?I?I
4 4
ICPC
CPCI
ICPC
CPCI
2 2
??
??
yes
ICICICI
CPCPCPC
ICICICI
CPCPCPC
ICICICI
no
yes
IC
PC