TSS '22 CC P3 - Treasure Hunt in the Jungle

View as PDF

Submit solution

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 R rows and C columns, determine the maximum amount of treasure chests you are able to loot.

Constraints

2 \le R, C \le 1000

Input Specification

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

The next R lines of input each contain C 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

Comments

There are no comments at the moment.