A15547 | Cactus Wall
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Monocarp is playing Minecraft and wants to build a wall of cacti. He wants to build it on a field of sand of the size of $n \times m$ cells. Initially, there are cacti in some cells of the field. Note that, in Minecraft, cacti cannot grow on cells adjacent to each other by side — and the initial field meets this restriction. Monocarp can plant new cacti (they must also fulfil the aforementioned condition). He can't chop down any of the cacti that are already growing on the field — he doesn't have an axe, and the cacti are too prickly for his hands.
Monocarp believes that the wall is complete if there is no path from the top row of the field to the bottom row, such that:
- each two consecutive cells in the path are adjacent by side;
- no cell belonging to the path contains a cactus.
Your task is to plant the minimum number of cacti to build a wall (or to report that this is impossible).
Monocarp believes that the wall is complete if there is no path from the top row of the field to the bottom row, such that:
- each two consecutive cells in the path are adjacent by side;
- no cell belonging to the path contains a cactus.
Your task is to plant the minimum number of cacti to build a wall (or to report that this is impossible).
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^3$ ) — number of test cases.
The first line of each test case contains two integers $n$ and $m$ ( $2 \le n, m \le 2 \cdot 10^5$ ; $n \times m \le 4 \cdot 10^5$ ) — the number of rows and columns, respectively.
Then $n$ rows follow, $i$ -th row contains a string $s_i$ of length $m$ , where $s_{i, j}$ is '\#', if a cactus grows at the intersection of the $i$ -th row and the $j$ -th column. Otherwise, $s_{i, j}$ is '.'.
The sum of $n \times m$ over all test cases does not exceed $4 \cdot 10^5$ .
The first line of each test case contains two integers $n$ and $m$ ( $2 \le n, m \le 2 \cdot 10^5$ ; $n \times m \le 4 \cdot 10^5$ ) — the number of rows and columns, respectively.
Then $n$ rows follow, $i$ -th row contains a string $s_i$ of length $m$ , where $s_{i, j}$ is '\#', if a cactus grows at the intersection of the $i$ -th row and the $j$ -th column. Otherwise, $s_{i, j}$ is '.'.
The sum of $n \times m$ over all test cases does not exceed $4 \cdot 10^5$ .
输出格式
For each test case, print NO in the first line if it is impossible to build a cactus wall without breaking the rules. Otherwise, print YES in the first line, then print $n$ lines of $m$ characters each — the field itself, where the $j$ -th character of the $i$ -th line is equal to '\#', if there is a cactus on the intersection of the $i$ -th row and the $j$ -th column, otherwise it is '.'. If there are multiple optimal answers, print any of them.
输入输出样例
输入 #1
4 2 4 .#.. ..#. 3 3 #.# ... .#. 5 5 ..... ..... ..... ..... ..... 4 3 #.. .#. #.# ...
输出 #1
YES .#.# #.#. NO YES ....# ...#. ..#.. .#... #.... YES #.. .#. #.# ...
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted