100 atcoder#ABC191C. [ABC191C] Digital Graffiti
[ABC191C] Digital Graffiti
Score : points
Problem Statement
We have a grid with rows and columns. Let be the square at the -th row from the top and -th column from the left.
Each square is painted black or white. If is #
, is painted black; if is .
, is painted white.
It is guaranteed that the outermost squares are white. That is, the squares that can be represented as , , , or are white.
Consider the part of the grid that is painted black as a polygon. How many sides does it have (at least)?
Here, it is guaranteed that the part painted black forms a polygon without self-intersection, that is, the following holds:
- at least one square is painted black;
- we can travel between any two squares painted black by repeatedly moving up, down, left, or right while going through only black squares;
- we can travel between any two squares painted white by repeatedly moving up, down, left, or right while going through only white squares. (Note that the outermost squares in the grid are all painted white.)
Constraints
- is
#
or.
. - and are
.
. - and are
.
. - The part painted black forms a polygon without self-intersection.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number such that the part painted black can be seen as an -gon.
5 5
.....
.###.
.###.
.###.
.....
4
If we use a coordinate system where the top-left, bottom-left, top-right, and bottom-right corners of the grid are , , , and , the given figure is a quadrilateral whose vertices are , , , and .