No.2456 Stamp Art
タグ : / 解いたユーザー数 64
作問者 :
srjywrdnprkt
/ テスター :
👑 Problem Statement
There is a grid $X$ with $H$ rows and $W$ columns, where each cell is painted white or black. The colors of the cells of grid $X$ are represented by $H$ strings $S_1, \cdots, S_H$ of length $W$ consisting of # and .: if the $j$-th character of $S_i$ is #, the cell $(i, j)$ in the $i$-th row from the top and the $j$-th column from the left is black, and if it is ., the cell is white.
Grid $X$ is said to be generable by a stamp of size $k$ if, for a grid $Y$ with $H$ rows and $W$ columns whose cells are all white, it is possible to choose a positive integer $k$ that is at most $H$ and at most $W$ and make it match grid $X$ by performing the following operation any number of times.
(Operation)
Choose a pair of integers $(i, j)$ satisfying $1 \leq i \leq H-k+1$ and $1 \leq j \leq W-k+1$, and for all integers $(l, m)$ satisfying $i \leq l \leq i+k-1$ and $j \leq m \leq j+k-1$, if the color of cell $(l, m)$ of grid $Y$ is white, repaint that cell black.
Find the maximum size of a stamp that can generate grid $X$.
Input
$H\ W$ $S_1$ $\vdots$ $S_H$
The input satisfies the following constraints.
- $H, W$ are integers
- $1 \leq H \leq 2000$
- $1 \leq W \leq 2000$
- $S_i$ is a string of length $W$ consisting only of
#and. - There exists at least $1$ pair $(i, j)$ such that the $j$-th character of $S_i$ is
#.
Output
Print the maximum size of a stamp that can generate grid $X$. Print a newline at the end.
Sample
Sample 1
Input
3 3 ##. ### .##
Output
2
Grid $Y$ is initially in the following state.
Consider the case $k=2$.
First, choose $(1,1)$ and perform the operation. Grid $Y$ then becomes as follows.
Next, choose $(2,2)$ and perform the operation. Grid $Y$ then becomes as follows, which matches grid $X$.
When $k\geq 3$, grid $X$ cannot be generated, so the answer is $2$.
Sample 2
Input
3 3 ### ### ###
Output
3
When $k=3$, it suffices to perform the operation on $(1,1)$.
Sample 3
Input
5 6 ###.## ##.### #####. .###.. ######
Output
1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。