A9801 | Arthur and Walls
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of the city with a nice price.
Plan of the apartment found by Arthur looks like a rectangle $n×m$ consisting of squares of size $1×1$ . Each of those squares contains either a wall (such square is denoted by a symbol "\*" on the plan) or a free space (such square is denoted on the plan by a symbol ".").
Room in an apartment is a maximal connected area consisting of free squares. Squares are considered adjacent if they share a common side.
The old Arthur dream is to live in an apartment where all rooms are rectangles. He asks you to calculate minimum number of walls you need to remove in order to achieve this goal. After removing a wall from a square it becomes a free square. While removing the walls it is possible that some rooms unite into a single one.
Plan of the apartment found by Arthur looks like a rectangle $n×m$ consisting of squares of size $1×1$ . Each of those squares contains either a wall (such square is denoted by a symbol "\*" on the plan) or a free space (such square is denoted on the plan by a symbol ".").
Room in an apartment is a maximal connected area consisting of free squares. Squares are considered adjacent if they share a common side.
The old Arthur dream is to live in an apartment where all rooms are rectangles. He asks you to calculate minimum number of walls you need to remove in order to achieve this goal. After removing a wall from a square it becomes a free square. While removing the walls it is possible that some rooms unite into a single one.
输入格式
The first line of the input contains two integers $n,m$ ( $1<=n,m<=2000$ ) denoting the size of the Arthur apartments.
Following $n$ lines each contain $m$ symbols — the plan of the apartment.
If the cell is denoted by a symbol "\*" then it contains a wall.
If the cell is denoted by a symbol "." then it this cell is free from walls and also this cell is contained in some of the rooms.
Following $n$ lines each contain $m$ symbols — the plan of the apartment.
If the cell is denoted by a symbol "\*" then it contains a wall.
If the cell is denoted by a symbol "." then it this cell is free from walls and also this cell is contained in some of the rooms.
输出格式
Output $n$ rows each consisting of $m$ symbols that show how the Arthur apartment plan should look like after deleting the minimum number of walls in order to make each room (maximum connected area free from walls) be a rectangle.
If there are several possible answers, output any of them.
If there are several possible answers, output any of them.
输入输出样例
输入 #1
5 5 .*.*. ***** .*.*. ***** .*.*.
输出 #1
.*.*. ***** .*.*. ***** .*.*.
输入 #2
6 7 ***.*.* ..*.*.* *.*.*.* *.*.*.* ..*...* *******
输出 #2
***...* ..*...* ..*...* ..*...* ..*...* *******
输入 #3
4 5 ..... ..... ..*** ..*..
输出 #3
..... ..... ..... .....
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted