시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB33191963.333%

문제

A car showroom is one of the few places where cars can be found indoors. Showrooms often have many cars, even above ground level! As cars are sold and new cars are bought in to sell, the cars must be moved carefully out of the showroom.

Clearly employees only wish to move cars if they have to. So, given a map of a showroom including its walls, doors and where the cars are, and the co-ordinates of the car to move, how many cars must be moved?

Cars can be rotated on the spot, but can only be moved through a completely empty space and not diagonally. Doors are always wide enough to move a car through.

입력

  • One line containing two integers R, C (3 ≤ R, C ≤ 400), the size of the showroom in rows and columns.
  • Another R lines, each containing a string of C characters with the following meaning:
    • ’#’: a wall;
    • ’c’: a car;
    • ’D’: a door in a wall.
  • The first and last lines must be walls or doors. The first and last characters in a row must be walls or doors.
  • The next line will contain two integers r (1 < r < R), and c (1 < c < C), the co-ordinates of the car to move. 1, 1 is the top-left corner.

출력

  •  One line containing one integer: the smallest number of cars that need to be moved (including the car we are moving) to allow our desired car to leave the building.

예제 입력 1

4 5
#####
#cDc#
#c#cD
#####
3 2

예제 출력 1

4

예제 입력 2

10 10
##########
#cc#ccccc#
#cc#cccccD
#cccccccc#
########c#
#cccccccc#
###cccccc#
#c#cccccc#
#cccccccc#
##########
2 2

예제 출력 2

11

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > The UK & Ireland Programming Contest > UKIEPC 2016 E번

  • 문제를 만든 사람: Jim Grimmett