Towers
Time limit2sMemory limit1024 MB
Given a grid of towers, print the smallest connected, row- and column-convex set of cells that contains all of them.
- Level
Medium6 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
Richmond Valentine built cell towers through which he plans to send signals to the SIM cards of his company. Now he wants to find the area covered by his towers.
The map of the Earth is a grid of rows and columns. Each tower occupies exactly one cell. A set of cells is called connected if every cell in it can be reached from every other cell by moving across cell borders while staying inside the set. A connected set is called cell-convex if every vertical and horizontal line intersects it in at most one contiguous segment. Valentine considers the towers to cover the minimal connected cell-convex figure that contains all the towers he built. Find this area.
Input
The first line contains integers and (), the dimensions of the Earth. The next lines each contain characters describing the map. If cell holds a tower, the -th character of the -th line is *, otherwise it is ..
Output
Print lines of characters each. If cell lies in the covered area, the -th character of the -th line must be *, otherwise it must be .. If there are multiple answers, print any of them.