#GD0000089. Các hồ ở Berland (Lakes in Berland)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các hồ ở Berland (Lakes in Berland)
Lakes in Berland
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A map is an grid of water (.) and land (*). Four-directionally connected water cells form a component. A component is a lake only if it does not touch the map boundary; boundary-touching water is connected to the ocean. At least lakes exist initially. Convert the fewest water cells to land so exactly lakes remain, then output the number changed and the resulting grid.
Input
The first line contains . The next lines each contain exactly characters, each . or *.
Output
Print the minimum number of converted cells, followed by the resulting grid rows. Any optimal resulting map is accepted.
Subtasks
- Subtask 1 (20 points): ; ; the original map contains at least lakes.
- Subtask 2 (30 points): ; ; the original map contains at least lakes.
- Subtask 3 (50 points): ; ; the original map contains at least lakes.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Explanation
The two water cells in row form a lake of size . The isolated water cell in row forms a lake of size . The bottom-row water touches the boundary and is not a lake. Filling the one-cell lake leaves exactly one lake at a cost of .