atcoder#ABC274G. [ABC274G] Security Camera 3
[ABC274G] Security Camera 3
Score : points
Problem Statement
There is a grid with rows from top to bottom and columns from left to right. Let denote the square at the -th row from the top and -th column from the left.
Square is occupied by an obstacle if #
, and is empty if .
.
Takahashi will install some surveillance cameras in the grid.
A surveillance camera can be placed at a square without an obstacle, in one of the four directions: up, down, left, or right. Multiple surveillance cameras may be placed at the same square.
Each surveillance camera monitors the square it is placed at, and the squares in the direction it is placed in, as far as there is no obstacle in between.
At least how many surveillance cameras are needed to monitor all squares without an obstacle?
Constraints
- is
.
or#
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
3 3
...
.#.
...
4
For example, if we install two surveillance cameras at square facing right and down, and another two at square facing up and left, all squares without an obstacle will be monitored.
3 5
...##
.#...
...#.
5
For example, if we install two surveillance cameras at square facing right and down, another at square facing left, and another two at square facing left and down, all squares without an obstacle will be monitored.
Note that the camera at square facing left cannot monitor square , since there is an obstacle in between at square .
14 107
...........................................................................................................
...........................................................................................................
..#########..###....###########..###.......###...###########..####.......###...###########...###########...
..########..###....###########....###.....###...###########...#####......###..###########...###########....
..#######..###.....###.............###...###....###...........######.....###..###...........###............
..######..###......###..............###.###.....###...........###.###....###..###...........###............
..#####..###.......############......#####......############..###..###...###..###...........############...
..####....###......############.......###.......############..###...###..###..###...........############...
..###......###.....###................###.......###...........###....###.###..###...........###............
..##........###....###................###.......###...........###.....######..###...........###............
..#..........###...############.......###.......############..###......#####..############..############...
..............###...###########.......###........###########..###.......####...###########...###########...
...........................................................................................................
...........................................................................................................
91