Олимпиадный тренинг

Задача 30781. Sea battle - 3


Задача

Темы: Очередь
Everyone knows the exciting game "Battleship". Now you can play Sea Battle not only with a neighbor on your desk, but also with a computer. The game with the computer is played on a rectangular field of arbitrary sizes N×M, where N is the number of rows, M is the number of columns. The Sea Battle World Championship is approaching. It is planned to broadcast it in real time: show a map with ships and display statistics: the number of intact, damaged and destroyed ships on the field. It is required to write a program to calculate statistics.
 
Ship on the field — this is a connected figure, standing from one or more adjacent cells that have a common side. Ships can be absolutely any shape and size!
 
Input
The first line contains two integers N and M (\(1<= N,M <= 10^3\) ), separated by spaces. These are the dimensions of the playing field. Next come N lines of M characters - a description of the playing field. The English letter 'X' denotes a padded ship cell, 'S' - unlined ship cell, '-' – free water space.
 
Output
In your answer, output three numbers separated by a space:
- number of whole ships;
- number of wrecked ships;
- number of destroyed ships.
 
Examples
# Input Output
1
3 8
---SSS--
XX--S-X-
X-S---S-
2 1 1