QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#15626. ICPC Board

統計

作为一名考古学家,你在古城遗址中发现了一块矩形木板。木板被划分为网格,每个格子最初似乎都刻有字母 ‘C’、‘I’ 或 ‘P’ 中的一个。然而,由于岁月的侵蚀,现在有些字母已经无法辨认。

在调查过程中,你提出了以下假设:木板上任意 $2 \times 2$ 的格子区域最初都包含两个 ‘C’、一个 ‘I’ 和一个 ‘P’。

你现在需要检查该假设是否与发现的木板一致。如果一致,请给出一个符合该假设的原始字母排列的可能性。

输入格式

输入包含一个或多个测试用例。输入的第一行包含一个整数 $t$ ($1 \le t \le 500$),表示测试用例的数量。接下来是 $t$ 个测试用例的描述,每个测试用例的格式如下:

$n$ $m$ $c_{1,1}$ $c_{1,2}$ $\dots$ $c_{1,m}$ $c_{2,1}$ $c_{2,2}$ $\dots$ $c_{2,m}$ $\vdots$ $c_{n,1}$ $c_{n,2}$ $\dots$ $c_{n,m}$

每个测试用例的第一行包含两个整数 $n$ 和 $m$ ($2 \le n \le 1000$, $2 \le m \le 1000$),分别表示木板的行数和列数。接下来的 $n$ 行,每行包含 $m$ 个字符,描述了发现的木板。第 $i$ 行的第 $j$ 个字符 $c_{i,j}$ 为 ‘C’、‘I’、‘P’ 或 ‘?’ 中的一个。如果 $c_{i,j}$ 是 ‘C’、‘I’ 或 ‘P’,则第 $i$ 行第 $j$ 列的格子可以识别出该字母。如果 $c_{i,j}$ 是 ‘?’,则该格子的字母无法辨认。

所有测试用例的 $n$ 之和不超过 1000,$m$ 之和也不超过 1000。

输出格式

对于每个测试用例,如果假设与发现的木板不一致,则输出 no。否则,第一行输出 yes,随后输出 $n$ 行,表示符合假设的原始字母排列的一种可能性。这 $n$ 行中的每一行应包含 $m$ 个字符。第 $i$ 行的第 $j$ 个字符应为第 $i$ 行第 $j$ 列格子中的字母。如果存在多种可能的排列,你可以输出其中任意一种。

样例

输入 1

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
??
??

输出 1

yes
ICICICI
CPCPCPC
ICICICI
CPCPCPC
ICICICI
no
yes
IC
PC

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.