시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB34181852.941%

문제

Your friend Ellie owns a local parcel delivery business called Grid City Parcel Courier (GCPC) which operates in Grid City, a town where all houses are aligned on a rectangular grid of streets. Each house is placed at the intersection of two streets, one running in north-south direction (vertically) and one running in east-west direction (horizontally). There are $w$ vertical streets and $h$ horizontal streets, resulting in a $h\times w$ grid of houses.

To grow her business, Ellie wants to start offering parcel pickup too. However, the mayor of Grid City recently decided that all streets will be one-way streets during the day to combat traffic jams. During this time, the streets of Grid City can only be passed from north to south or west to east, respectively.

Figure G.1: Visualization of the grid of one-way streets given in the first sample input.

Ellie already rented a large garage located at the city's northwesternmost intersection, from which her drivers will start their journeys to collect parcels. She asked you to help her figure out how many drivers she needs to hire to collect all parcels during the day and bring them to her logistics center located at the city's southeasternmost intersection.

입력

The input consists of:

  • One line with two integers $h$ and $w$ ($1 \le h,w \le 2\,000$), the height and width of the grid.
  • $h$ lines, each with $w$ characters which are either C, indicating the house of a customer where a parcel has to be collected, or \_, indicating a house where nothing has to be collected.

출력

Output the minimal number of drivers required to collect all parcels while all streets are one-way streets.

예제 입력 1

4 4
__C_
C_C_
_C_C
_CCC

예제 출력 1

2

예제 입력 2

4 6
CC____
_CCC__
___C_C
C__CCC

예제 출력 2

2

예제 입력 3

3 5
CC__C
_C_CC
CCCCC

예제 출력 3

3

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2021 G번

  • 문제를 만든 사람: Nathan Maier