QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 256 MB Points totaux : 100

#4176. Cell Exploration

Statistiques

In biology class, the teacher introduces cells to the students. To help students understand, the teacher defines a type of cell in an $N \times M$ matrix, where the matrix contains only '#' and '.':

A cell consists of a nucleus, cytoplasm, and a cell membrane. The nucleus is a 4-connected (connected horizontally or vertically) component consisting entirely of '#', and it must be solid, meaning there cannot be a 4-connected '.' component completely enclosed by it (complete enclosure means the '.' component is not adjacent to the matrix boundary, and all its 4-adjacent cells belong to the '#' component containing it). The cell membrane is an 8-connected (connected horizontally, vertically, or diagonally) non-solid component consisting entirely of '#'. The cell membrane encloses exactly one 4-connected region, and this region contains exactly one nucleus, with all remaining positions in this region being '.'.

All connected components must be maximal, meaning that for an 8-connected component, no '#' can be found in its surroundings that is 8-connected to any '#' of this component; similarly, for a 4-connected component, no '#' can be found in its surroundings that is 4-connected to any '#' of this component.

Now, the teacher has drawn a picture and asks little E to count the number of cells in the picture and change any '#' that does not belong to any cell into '.'.

Input

The first line contains two space-separated positive integers $N$ and $M$, representing the height and width of the matrix. The next $N$ lines contain the $N \times M$ matrix, which contains only '#' and '.', with no extra characters.

Output

The first line contains an integer representing the number of cells in the input matrix. The next $N$ lines contain the $N \times M$ matrix, which contains only '#' and '.', representing the modified picture.

Examples

Input 1

12 13
.###..#####..
#...#.#....#.
#.#.#.#..#.#.
#...#..#...#.
.###.#..###..
....#..##...#
..........###
##########..#
#...........#
#.###...###.#
#...........#
#############

Output 1

1
......#####..
......#....#.
......#..#.#.
.......#...#.
........###..
.......##....
.............
.............
.............
.............
.............
.............

Input 2

9 14
#########.....
#.......#....#
#.#####.#...#.
#.#...#.#..#..
#.#.#.#.#.#..#
#.#...#.#..#..
#.#####.#...#.
#.......#....#
#########.....

Output 2

1
..............
..............
..#####.......
..#...#.......
..#.#.#.......
..#...#.......
..#####.......
..............
..............

Input 3

7 15
#######.#######
#.....#.#.....#
#.###.#.#.###.#
#.#.#.#.#.#...#
#.###.#.#.###.#
#.....#.#.....#
#######.#######

Output 3

1
........#######
........#.....#
........#.###.#
........#.#...#
........#.###.#
........#.....#
........#######

Constraints

For 20% of the data, $1 \le N, M \le 20$. For another 20% of the data, all '#' belong to a valid cell. For 100% of the data, $1 \le N, M \le 1,000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.