#K32842. Taco Treasure Hunt

    ID: 24955 Type: Default 1000ms 256MiB

Taco Treasure Hunt

Taco Treasure Hunt

In this problem, you are given an n×m grid where each cell is either empty (denoted by '.') or contains a treasure chest (denoted by 'T'). Starting from an empty cell, you can collect treasure chests that are adjacent to it (in the 8 possible directions: up, down, left, right, and the four diagonals). Once you collect a treasure chest, you can continue collecting all connected treasure chests (i.e. those that are adjacent to a collected treasure) recursively. The objective is to determine the maximum number of treasure chests you can collect by choosing the best starting empty cell.

Formally, let the grid indices be 0-indexed. Two treasure cells are connected if they share a common side or a corner. If you start from an empty cell at position (i, j), you can only collect treasures that are directly adjacent (in one of the 8 directions) to it, and then extend your search to other treasures adjacent to any collected treasure. The answer is computed as (\max_{grid[i][j]=='.'};\text{collected}(i,j)), where (\text{collected}(i,j)) is the total number of treasures collected starting from cell (i, j).

inputFormat

The first line of input contains two integers n and m (the number of rows and columns). The following n lines each contain a string of length m, representing the grid. Each character is either '.' or 'T'.

outputFormat

Output a single integer which is the maximum number of treasure chests that can be collected starting from the best empty cell.## sample

1 1
.
0

</p>