Count occurrences of each of five tetromino shapes (rotations allowed, no flips) in a grid colored so adjacent figures differ.
Medium6ImplementationGraphBFSBrute forceNo attempts yetTime limit1sMemory limit64 MBIvica is writing a computer game. The part he has finished places five kinds of Tetris figures in a grid. Before a figure goes into the grid it can be rotated by 90 degrees any number of times and it can be coloured. There is no flipping. A figure cannot be placed if it would leave the grid or overlap a figure that is already there.
The five figures are these.
![]() | ![]() | ![]() | ![]() | ![]() |
|---|---|---|---|---|
| Figure 1 | Figure 2 | Figure 3 | Figure 4 | Figure 5 |
The same five figures written with characters, where # is a cell the figure occupies:
Fig 1 Fig 2 Fig 3 Fig 4 Fig 5
## #### .## ##. .#.
## ##. .## ###
Figure 3 and figure 4 are mirror images of each other, so no rotation turns one into the other and they count separately.
While Ivica was at school, his sister Marica started the game and placed figures in the grid, rotating and colouring them as she liked. Two adjacent figures always have different colours. Two figures count as adjacent when they share a side or when they touch only at a corner.
Ivica came back and found his sister's figures still in the grid. Count how many of each figure the grid holds.
The first line contains the number of rows N and the number of columns M of the grid (1≤N,M≤10). Each of the next N lines contains one row of the grid as M characters.
Each character is either ., which is an empty cell, or a lowercase English letter, which is part of a figure. Different letters are different colours, and the four cells of one figure all carry the same letter.
Print exactly five lines. Line i contains how many times figure i appears in the grid.
The picture below shows the grid of the third example.
