TCCC '23 Dec P1 - The Jolly Mines

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

After being arrested by the North Pole Police Department (NPPD) for aggregate grand thefts from their little "Grinching" scheme, the elves were now all together in Santa's infamous "Jolly" coal mines. Turns out Santa had silently updated the security systems to allow the elves to individually build up a theft profile of over $30,000 each, escalating their petty thefts to an aggregate felony. In the spirit of giving or spite, the disciplinary elf Brian decided that the elves should be allowed to apply for parole and reintegration into Santa's factory network if they manage to exhaust all of the exposed coal in the mine.

Coughing on the soot-filled blackness of the poorly ventilated mine, the elves decided to cave into Santa's terms agreeing that with the mass elf numbers, they could easily cover every inch of the mine and remove coal deposits before the flames of their improvised torches suck out all of the oxygen available to breathe and they all faint.

Each elf is given an area to cover in the mine where they must count how many coals are reachable from their position.

An elf starts at the letter S in their plot in the mine, and the coals in the mine are located at position C.

. denotes an open space, while #represents a wall in the mine.

As a living elf, you can move only up/down/left/right, not through walls, and not outside of the designated mine area's bounds.

Input Specifications

The first line consists of two integers L (2 \le L \le 1000) and W (2 \le W \le 1000) representing the length and width of the mines.

The next L lines, each contain W characters - the grid of the actual mine area.

Output Specification

Output the amount of reachable coals in the mine.

Sample Input 1

3 5
#S###
C...C
###C#

Sample Output 1

3

Sample Input 2

4 5
#S###
C...C
###C#
CC#C#

Sample Output 2

4

Explanation of Sample Output 2

An elf can access a cluster of coal deposits but not walled off coal.


Comments

There are no comments at the moment.