Flea

시간 제한2초메모리 제한1024 MB

요약
각 칸의 화살표 방향으로 최대 K칸씩 점프해 사각형 밖으로 나갈 수 있는 시작 칸의 수를 센다.
난이도

어려움10점 중 8점

유형
그래프, DFS, 동적 계획법, 구현
정답자
아직 제출이 없습니다

문제

You have placed glues on each cells of an N×MN\times M grid to create a rectangular flea trap. Each glue has a weak direction; if a flea on the glue jumps towards its weak direction, the flea can jump out of the glue.

More precisely, each glue is represented by U, D, L, or R, meaning up, down, left, and right respectively.

Fleas can jump at most KK cells in one jump. If a flea jumps out of the rectangle, we say that the flea has escaped.

You became curious about how effective your trap is. If a flea that is placed on a cell of the trap can escape after consecutive jumps, we call the cell an escapable cell. Your task is to count the number of escapable cells.

입력

In the first line, the trap sizes NN, MM and the jump limit KK are given, separated by spaces.

For the next NN lines, each line contains a string of length MM, indicating the weak direction of each cell.

출력

Print the number of escapable cells.

제한

  • NN, MM, and KK are integers.
  • 1≤N≤2,0001\le N\le 2\\, 000
  • 1≤M≤2,0001\le M\le 2\\, 000
  • 1≤K≤2,0001\le K\le 2\\, 000
  • Each string consists of U, D, L, or R.

예제1

  1. 예제 1

    입력
    5 5 2
    DDDRD
    DDDDD
    RDLUL
    UURUU
    UUUUU
    
    예상 출력
    14