COCI '17 Contest 1 #2 Tetris

View as PDF

Submit solution


Points: 5
Time limit: 0.6s
Memory limit: 64M

Problem type

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.

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 Specification

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 Specification

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.

Scoring

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.

Sample Input 1

4 5
aaaa.
.bb..
.bbxx
...xx

Sample Output 1

2
1
0
0
0

Sample Input 2

4 5
.aab.
aabb.
.cbaa
cccaa

Sample Output 2

1
0
1
1
1

Sample Input 3

5 7
.c.....
ccdddd.
caabbcc
aabbacc
...aaa.

Sample Output 3

1
1
2
1
1

Explanation for Sample Output 3

The following image depicts the Tetris matrix when Ivica came back to his computer:


Comments

There are no comments at the moment.