#abc233g. G - Strongest Takahashi

G - Strongest Takahashi

Score : 600600 points

问题描述

存在一个 N×NN \times N 的网格,其中某些格子上放置有方块。

该网格由 NN 个字符串 S1,S2,,SNS_1,S_2,\dots,S_N 描述,如下所示:

  • 如果 SiS_i 的第 jj 个字符是 #,则在从顶部数第 ii 行、从左边数第 jj 列的格子上有一个方块。
  • 如果 SiS_i 的第 jj 个字符是 ., 则在从顶部数第 ii 行、从左边数第 jj 列的格子上没有方块。

Takahashi 可以执行以下操作零次或多次:

  • 首先,选择一个整数 DD,其取值范围在 11NN(包含)之间,并在网格内选取一个 D×DD \times D 的子方格。
  • 然后,消耗 DD 点体力值来摧毁子方格内的所有方块。

请找出摧毁所有方块所需的最小体力值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a N×NN \times N grid, with blocks on some squares.
The grid is described by NN strings S1,S2,,SNS_1,S_2,\dots,S_N, as follows.

  • If the jj-th character of SiS_i is #, there is a block on the square at the ii-th row from the top and jj-th column from the left.
  • If the jj-th character of SiS_i is ., there is not a block on the square at the ii-th row from the top and jj-th column from the left.

Takahashi can do the operation below zero or more times.

  • First, choose an integer DD between 11 and NN (inclusive), and a D×DD \times D subsquare within the grid.
  • Then, consume DD stamina points to destroy all blocks within the subsquare.

Find the minimum number of stamina points needed to destroy all the blocks.

Constraints

  • NN is an integer.
  • 1N501 \le N \le 50
  • SiS_i consists of # and ..
  • Si=N|S_i|=N

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the answer as an integer.

Sample Input 1

5
##...
.##..
#.#..
.....
....#

Sample Output 1

4

By choosing the subsquares below, Takahashi will consume 44 stamina points, which is optimal.

  • The 3×33 \times 3 subsquare whose top-left square is at the 11-st row from the top and 11-st column from the left.
  • The 1×11 \times 1 subsquare whose top-left square is at the 55-th row from the top and 55-th column from the left.

Sample Input 2

3
...
...
...

Sample Output 2

0

There may be no block on the grid.

Sample Input 3

21
.....................
.....................
...#.#...............
....#.............#..
...#.#...........#.#.
..................#..
.....................
.....................
.....................
..........#.....#....
......#..###.........
........#####..#.....
.......#######.......
.....#..#####........
.......#######.......
......#########......
.......#######..#....
......#########......
..#..###########.....
.........###.........
.........###.........

Sample Output 3

19

update @ 2024/3/10 10:09:30