CF1667F.Yin Yang
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a rectangular grid with n rows and m columns. n and m are divisible by 4. Some of the cells are already colored black or white. It is guaranteed that no two colored cells share a corner or an edge.
Color the remaining cells in a way that both the black and the white cells becomes orthogonally connected or determine that it is impossible.
Consider a graph, where the black cells are the nodes. Two nodes are adjacent if the corresponding cells share an edge. If the described graph is connected, the black cells are orthogonally connected. Same for white cells.
你被给定一个 n 行 m 列的矩形网格,其中 n 和 m 均能被 4 整除。部分格子已被染成黑色或白色。保证所有已染色的格子互不相邻(即任意两个已染色格子既不共享边,也不共享角)。
请将剩余格子染色,使得所有黑色格子构成正交连通(orthogonally connected),且所有白色格子也构成正交连通;或者判断这是不可能的。
定义一个图:以所有黑色格子为顶点;若两个黑色格子共享一条边,则在对应顶点间连一条边。若该图是连通的,则称黑色格子是正交连通的。白色格子同理。
输入格式
The input consists of multiple test cases. The first line of the input contains a single integer t (1≤t≤4000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n, m (8≤n,m≤500, n and m are divisible by 4) — the number of rows and columns.
Each of the next n lines contains m characters. Each character is either 'B', 'W' or '.', representing black, white or empty cell respectively. Two colored (black or white) cell does not share a corner or an edge.
It is guaranteed that the sum of n⋅m over all test cases does not exceed 250000.
输入包含多个测试用例。输入的第一行包含一个整数 t(1≤t≤4000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(8≤n,m≤500,且 n 和 m 均能被 4 整除),分别表示行数和列数。
接下来的 n 行,每行包含 m 个字符。每个字符为 'B'、'W' 或 '.',分别代表黑色格子、白色格子或空格子。任意两个已着色(黑色或白色)的格子不共享顶点或边。
保证所有测试用例中 n⋅m 的总和不超过 250000。
输出格式
For each testcase print "NO" if there is no solution, otherwise print "YES" and a grid with the same format. If there are multiple solutions, you can print any.
对于每个测试用例,若无解则输出 "NO";否则输出 "YES" 以及一个格式相同的网格。若存在多个解,输出任意一个即可。
输入输出样例
输入#1
4 8 8 .W.W.... .....B.W .W.W.... .....W.W B.B..... ....B.B. B.W..... ....B.B. 8 8 B.W..B.W ........ W.B..W.B ........ ........ B.W..B.W ........ W.B..W.B 8 12 W.B......... ....B...B.W. B.B......... ....B...B.B. .B.......... ........B... .W..B.B...W. ............ 16 16 .W............W. ...W..W..W.W.... .B...........B.W ....W....W...... W......B....W.W. ..W.......B..... ....W...W....B.W .W....W....W.... ...B...........W W.....W...W..B.. ..W.W...W......B ............W... .W.B...B.B....B. .....W.....W.... ..W......W...W.. W...W..W...W...W
输出#1
YES BWWWWWWW BWBBBBBW BWBWWWBW BWBWBWBW BWBWBWBW BWBBBWBW BWWWWWBW BBBBBBBW NO YES WWBBBBBBBBBB BWWWBBBBBBWB BBBWBBBWWWWB BBBWBBBWBBBB BBBWBBBWBBBB BBBWWWWWBBBB BWWWBBBWWWWB BBBBBBBBBBBB YES WWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWW WBBBBBBBBBBBBBWW WBBBWBWWWWBWWBWW WBBWWBBBWWBWWBWW WBWWWBWWWWBWWBWW WBBWWBBBWWBWWBWW WWBWWWWWWWWWWWWW WWBBBBBBBBBBBBWW WBBBWWWBWWWBWBWW WWWBWBBBWBBBWBBB WWWBWBWWWWWBWWBW WWWBWBBBWBBBWWBW WWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWW
说明/提示
Solution for test case 1:

Test case 2: one can see that the black and the white part can't be connected in the same time. So the answer is "NO".
测试用例 1 的解法:

测试用例 2:可以发现黑色部分和白色部分无法同时连通。因此答案为 “NO”。
输入解题思路,AI测评打分。不知道怎么写?