A16087 | Two-Colored Dominoes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is an $n\times m$ board divided into cells. There are also some dominoes on this board. Each domino covers two adjacent cells (that is, two cells that share a side), and no two dominoes overlap.
Piet thinks that this board is too boring and it needs to be painted. He will paint the cells of the dominoes black and white. He calls the painting beautiful if all of the following conditions hold:
- for each domino, one of its cells is painted white and the other is painted black;
- for each row, the number of black cells in this row equals the number of white cells in this row;
- for each column, the number of black cells in this column equals the number of white cells in this column.
Note that the cells that are not covered by dominoes are not painted at all, they are counted as neither black nor white.
Help Piet produce a beautiful painting or tell that it is impossible.
Piet thinks that this board is too boring and it needs to be painted. He will paint the cells of the dominoes black and white. He calls the painting beautiful if all of the following conditions hold:
- for each domino, one of its cells is painted white and the other is painted black;
- for each row, the number of black cells in this row equals the number of white cells in this row;
- for each column, the number of black cells in this column equals the number of white cells in this column.
Note that the cells that are not covered by dominoes are not painted at all, they are counted as neither black nor white.
Help Piet produce a beautiful painting or tell that it is impossible.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10\,000$ ). The description of the test cases follows.
The first line of each test case contains two integers $n$ and $m$ ( $2\le n, m\le 500$ ).
The next $n$ lines describe the tiling of the board, row by row from top to bottom. Each of these lines contains $m$ characters, describing the cells in the corresponding row from left to right. Each character is one of U, D, L, R, or ., meaning that the cell is covered with a top, bottom, left, right half of a domino or nothing, respectively. The tiling is guaranteed to be valid.
It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $250\,000$ .
The first line of each test case contains two integers $n$ and $m$ ( $2\le n, m\le 500$ ).
The next $n$ lines describe the tiling of the board, row by row from top to bottom. Each of these lines contains $m$ characters, describing the cells in the corresponding row from left to right. Each character is one of U, D, L, R, or ., meaning that the cell is covered with a top, bottom, left, right half of a domino or nothing, respectively. The tiling is guaranteed to be valid.
It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $250\,000$ .
输出格式
For each test case, output a single integer $-1$ if a beautiful painting does not exist. Otherwise, print $n$ lines, each containing $m$ characters, describing the colors in the corresponding row of a beautiful painting. Every character corresponding to a cell not covered by a domino must be . (a dot), and all other characters must be B if the corresponding cell is black or W if it is white.
If there are multiple solutions, print any of them.
If there are multiple solutions, print any of them.
输入输出样例
输入 #1
3 4 6 ..LR.. ULRU.. DLRDUU ..LRDD 5 4 .LR. .UU. UDDU D..D LR.. 2 2 .. ..
输出 #1
..WB.. WWBB.. BBWWWB ..BWBW -1 .. ..
In the first test case, the answer is illustrated below:
In the second test case, it is impossible to paint all cells the right way.
In the second test case, it is impossible to paint all cells the right way.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted