시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 1024 MB | 3 | 3 | 3 | 100.000% |
You are making a chocolate chip cookie using a machine that has a rectangular pan composed of unit squares. You have determined the shape of your cookie, which occupies some squares in that area. Each square of your cookie must be chocolate chipified.
To make the cookie you will repeatedly perform the following two steps:
The following example shows how to make a cookie of the shape shown on the left (s):
(s) (a1) (a2) (b1) (b2) -X-X- -D-D- -C-C- -C-C- -C-C- XXXXX -D-D- -C-C- DCDCD CCCCC XXXXX -DDD- -CCC- DCCCD CCCCC -XXX- --D-- --C-- -DCD- -CCC- --X-- ----- ----- --D-- --C--
First you place cookie dough in $8$ squares (a1). All squares become chipified after the first solution exposure (a2). You place cookie dough in $8$ more squares (b1). The second exposure makes every square chipified and completes the cookie (b2).
Your chocolate chip solution is expensive, so you want to ensure that you perform the exposure as few times as possible. Given a cookie shape, determine the minimum number of chocolate chip solution exposures required to make the cookie.
The first line of input contains two integers $n$ and $m$ ($1 \leq n, m \leq 1\,000$), indicating the pan has $n$ rows and $m$ columns of unit squares.
Each of the next $n$ lines contains a string of exactly $m$ characters, where each character is either "X
", representing a square occupied by your cookie, or "-
", representing an empty square.
The shape of your cookie occupies at least one square. Note that the shape may consist of multiple pieces that are disconnected.
Output the minimum number of chocolate chip solution exposures required to make your cookie.
5 5 -X-X- XXXXX XXXXX -XXX- --X--
2
4 5 --XXX --X-X X-XXX XX---
1
5 5 XXXXX XXXXX XXXXX XXXXX XXXXX
3
ICPC > Regionals > North America > Mid-Atlantic Regional > 2022 Mid-Atlantic USA Regional Contest > Division 1 C번
ICPC > Regionals > North America > South Central USA Regional > 2022 South Central USA Regional Contest > Division 1 C번
ICPC > Regionals > North America > Southeast USA Regional > 2022 Southeast USA Regional Programming Contest > Division 1 C번
ICPC > Regionals > North America > Mid-Atlantic Regional > 2022 Mid-Atlantic USA Regional Contest > Division 2 D번
ICPC > Regionals > North America > South Central USA Regional > 2022 South Central USA Regional Contest > Division 2 D번
ICPC > Regionals > North America > Southeast USA Regional > 2022 Southeast USA Regional Programming Contest > Division 2 D번
ICPC > Regionals > North America > North Central North America Regional > 2022 North Central NA Regional Contest C번
ICPC > Regionals > North America > Pacific Northwest Regional > 2022 ICPC Pacific Northwest Region > Division 2 K번