406633: GYM102465 I Mason's Mark

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Mason's Marktime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
A mason's mark is a symbol often found on dressed stones in buildings and other public structures. As Peter walks with his camera through Paris, he notices these marks on the wall of the Tour Jean-Sans-Peur. Every stone has one of the marks A, B or C, which are quite visible. He makes a black and white photo and observes :
  • The picture shows stones, and every stone contains exactly one mark.
  • All marks have one of the following shapes with $$$x$$$ and $$$y$$$ being arbitrary strictly positive integers, and possibly different for each mark. Note that marks are surrounded by white pixels and that marks cannot be rotated.
  • The picture contains some noise, which are black pixels surrounded by $$$8$$$ white pixels.
  • There are $$$3$$$ kinds of black pixels, corresponding respectively to the noise, the mason's marks, and the region around the stones.
  • Every white pixel belongs to the surface of a stone and some of them also belong to the interior of a mark.
  • The white pixels belonging to the surface of the same stone but not belonging to the interior of the mark are all connected with respect to vertical and horizontal adjacency. However, the surface of a stone may be non-convex.
  • The black pixels of the region around the stones are connected with respect to vertical, horizontal, diagonal, and anti-diagonal adjacency, which means that you can go from any black pixel of the region around the stones to any other such pixel by moving from one pixel to one of its eight adjacent pixels. All pixels of the border of the picture are black and belong to this region.

You are given a rectangular matrix representing a picture made by Peter. The '#' character represents a black pixel and the '.' character a white pixel. You should count how many stones are on the picture with the respective letters A, B, and C.

Input

The first line contains two integers $$$W$$$ and $$$H$$$. The next $$$H$$$ lines each contain a string of length $$$W$$$. The strings are composed of '.' and '#'.

Limits

  • $$$7 \le W \le 1000$$$;
  • $$$9 \le H \le 1000$$$.
Output

The output should consist of a single line, whose content is three integers $$$A$$$, $$$B$$$, and $$$C$$$ separated with single spaces, indicating the number of stones with the respective marks A, B, and C.

ExampleInput
26 15
##########################
##........######......#..#
#...###....#####..#......#
#...#.#....####.........##
#...###.....##....#####..#
#...#.#.....#.....#####..#
#...###.....#.....##.##..#
#........#..#.#...#####..#
#..###......#.....#####..#
#..#........#...#.##.##..#
#..#........#.....##.##..#
#..#...#.#..#...#.##.##..#
#..###......#............#
###....#....##....##.....#
##########################
Output
1 1 0
Note

Sample Explanation

There are black pixels forming a letter C. These pixels, however, belong to the region around the stones and do not form a mark since they are not surrounded by white pixels.

加入题单

算法标签: