#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 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 (), which is the number of test cases. The descriptions of the test cases follow, each in the following format.
The first line of a test case contains two integers and (, ). They represent the number of rows and columns of the board, respectively. The next lines, each containing characters, describe the discovered board. The -th character of the -th line, , is one of 'C', 'I', 'P', and '?'. If is 'C', 'I', or 'P', the cell in row and column is identifiable as having that letter. If is '?', the letter in that cell is indistinguishable.
The sum of 's over all the test cases does not exceed 1000. The same applies to .
输出格式
For each test case, if the hypothesis is not consistent with the discovered board, output in a single line. Otherwise, output in the first line, followed by lines representing one possibility of the original arrangement of the letters that aligns with the hypothesis. Each of these lines should contain characters. The -th character of the -th line should be the letter in the cell in row and column . 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