No.2946 Puyo
タグ : / 解いたユーザー数 138
作問者 :
Michirakara
/ テスター :
rotti_coder
t9unkubj
Problem Statement
You are given a grid $G$ with $H$ rows and $W$ columns consisting of uppercase English letters and ..
For every connected component of size $4$ or greater, simultaneously replace all cells belonging to it with ., and output the resulting grid.
Notes
Cells $c_1,c_2$ are connected if it is possible to get from cell $c_1$ to cell $c_2$ by repeatedly moving to a vertically or horizontally adjacent cell on which the same character is written.
A set of cells $S$ is a connected component if $S$ satisfies the following conditions.
- Any $2$ cells in $S$ are connected.
- No cell not contained in $S$ is connected to a cell contained in $S$.
Constraints
- $1\leq H\leq 1000$
- $1\leq W\leq 1000$
- $G_{i,j}(1\leq i\leq H, 1\leq j\leq W)$ is an uppercase English letter or
.
Input
$H\ W$
$G_{1,1}\ G_{1,2}\ \dots\ G_{1,W}$
$G_{2,1}\ G_{2,2}\ \dots\ G_{2,W}$
$\vdots$
$G_{H,1}\ G_{H,2}\ \dots\ G_{H,W}$
Output
Output the resulting grid with $H$ rows and $W$ columns after the replacement.
Print a newline at the end.
Sample
Sample 1
Input
4 4 AAAA ABCB ADDA AEEE
Output
.... .BCB .DDA .EEE
Note that parts that are not connected are not replaced, even if they have the same character.
Sample 2
Input
1 1 .
Output
.
Note that the input may contain ..
Sample 3
Input
3 3 ABB A.B AAB
Output
... ... ...
All clear!
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。