TSS '22 CC P3 - Treasure Hunt in the Jungle

View as PDF

Points: 7
Time limit: 4.0s
Memory limit: 1G

Author:
Problem type

You stumble across a jungle rumored to have ancient treasures in it. Luckily, you have a map of the jungle with the locations of the treasure chests.

Your map contains the following legend:

Symbol Description
. Terrain you may walk through
X A tree obstructing your path
S Your starting position
C A treasure chest

From any given position, you may travel to an adjacent square as long as it is not covered by a tree.

Given the contents of the map with rows and columns, determine the maximum amount of treasure chests you are able to loot.

Input Specification

The first line of input contains space-separated integers, and .

The next lines of input each contain characters, representing the contents of the map.

It is guaranteed that S will appear exactly once and all other characters will be present on the legend.

Output Specification

Output a single integer, the total number of treasure chests that are reachable from your starting position.

Sample Input

3 7
S..C.X.
XX..X.C
C...X..

Sample Output

2