atcoder#ABC233G. [ABC233G] Strongest Takahashi
[ABC233G] Strongest Takahashi
Score : points
Problem Statement
There is a grid, with blocks on some squares. The grid is described by strings , as follows.
- If the -th character of is
#
, there is a block on the square at the -th row from the top and -th column from the left. - If the -th character of is
.
, there is not a block on the square at the -th row from the top and -th column from the left.
Takahashi can do the operation below zero or more times.
- First, choose an integer between and (inclusive), and a subsquare within the grid.
- Then, consume stamina points to destroy all blocks within the subsquare.
Find the minimum number of stamina points needed to destroy all the blocks.
Constraints
- is an integer.
- consists of
#
and.
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
5
##...
.##..
#.#..
.....
....#
4
By choosing the subsquares below, Takahashi will consume stamina points, which is optimal.
- The subsquare whose top-left square is at the -st row from the top and -st column from the left.
- The subsquare whose top-left square is at the -th row from the top and -th column from the left.
3
...
...
...
0
There may be no block on the grid.
21
.....................
.....................
...#.#...............
....#.............#..
...#.#...........#.#.
..................#..
.....................
.....................
.....................
..........#.....#....
......#..###.........
........#####..#.....
.......#######.......
.....#..#####........
.......#######.......
......#########......
.......#######..#....
......#########......
..#..###########.....
.........###.........
.........###.........
19