Mock CCC '22 2 S5 - Kaguya Wants to go Window Shopping with Kei Shirogane

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 0.25s
Memory limit: 1G

Problem type

Kaguya is trying to plan out a shopping trip with Kei Shirogane. As a result, she will build Kei a mall!

The mall takes the form of an R \times C grid with an up escalator and a down escalator, as the mall is not on ground level. The mall has some pillars in it where construction cannot occur, but all empty squares are reachable from both escalators right now if movement is allowed between grid squares that share an edge.

Kaguya will build shops in some empty cells. Cells that are empty or contain escalators are walkable. An empty cell is a hallway if it is reachable from both escalators via walkable cells. A shop directly adjacent to a hallway can install a window facing the hallway.

Kaguya wants to maximize the number of windows that the mall builds to maximize the amount of window shopping she does with Kei. Compute this number.


4 \le R \cdot C \le 99

In tests worth 1 mark, \min(R, C) \le 1.

In tests worth an additional 2 marks, \min(R, C) \le 2.

In tests worth an additional 2 marks, \min(R, C) \le 3.

In tests worth an additional 2 marks, \min(R, C) \le 4.

In tests worth an additional 2 marks, \min(R, C) \le 5.

In tests worth an additional 2 marks, \min(R, C) \le 6.

Input Specification

The first line contains two integers R and C.

Each of the next R lines contains a string of C characters. Each character is one of .#UD, indicating an empty cell, pillar, up escalator, and down escalator, respectively.

Output Specification

Output the maximum number of windows that can be made in the mall.

Sample Input 1

4 5

Sample Output 1


Sample Input 2

4 4

Sample Output 2


Sample Input 3

3 2

Sample Output 3



There are no comments at the moment.