Problem list
Log in
#coci00454 · COCI 2017/2018 Contest 1

Tetris

Silver I 1.0 s 256 MB

Ivica is a passionate computer scientist. He recently started working on his first computer game: a clone of the popular Tetris. Although he’s far from being finished, his program supports placing five different Tetris figures shown in the image below in a matrix. Before placing it in the Tetris matrix, the figure can be rotated by 90 degrees an arbitrary number of times and coloured. Additionally, the current version of the game doesn’t support placing the figure if that would mean it goes out of the matrix boundaries or overlaps with another existing figure in the matrix. Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 While Ivica was in school, his sister Marica started the game and randomly rotated, coloured and placed the figures in a way that the adjacent figures are coloured differently. Two figures are adjacent if they share a common side or touch in the tip. When Ivica came back to his computer, he found the game running with the figures his sister placed. He wants to know how many of which figures there are in the Tetris matrix and he is asking you to help him solve this problem while he’s busy with improving the game.

Input

The first line of input contains positive integers $N$ and $M$ ($1 \le N$, $M \le 10$) that represent the number of rows and columns of the Tetris matrix. Each of the following $N$ lines contains $M$ characters that represent the matrix. Each character can be ‘.’ (dot) that represents a blank space or a lowercase letter of the English alphabet that represents a part of the figure. Different letters represent different colours, and the parts of the same figure are coloured the same.

Output

You must output exactly five rows. The i^{th} line must contain the number of appearances of the i^{th} figure in the game of Tetris.

Constraints

In test cases worth 20% of total points, only the first figure will appear. In test cases worth an additional 20% of total points, only the first two figures will appear. In test cases worth an additional 20% of total points, only the first three figures will appear. In test cases worth an additional 20% of total points, only the first four figures will appear.

Example 1

Input
4 5
aaaa.
.bb..
.bbxx
...xx
Output
2
1
0
0
0

Example 2

Input
4 5
.aab.
aabb.
.cbaa
cccaa
Output
1
0
1
1
1

Example 3

Input
5 7
.c.....
ccdddd.
caabbcc
aabbacc
...aaa.
Output
1
1
2
1
1
Source
COCI 2017/2018 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code