#P10379. [GESP202403 七级] 俄罗斯方块
[GESP202403 七级] 俄罗斯方块
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1147.
Problem Description
Student Xiao Yang filled a grid of size using different kinds of Tetris blocks.
The grid consists of colored cells. Xiao Yang now gives you this grid and asks you to compute how many different kinds of Tetris blocks appear in the grid.
If two cells of the same color are 4-connected (i.e., adjacent in one of the four directions: up, down, left, right), then the two cells are said to be directly connected. If two cells of the same color are both directly or indirectly connected to another cell of the same color, then the two cells are said to be indirectly connected. A Tetris block consists of one cell and all same-colored cells that are directly or indirectly connected to it. Two Tetris blocks are defined to be of the same kind if and only if one block can be translated to overlap exactly with the other; if two Tetris blocks have different colors, they are still considered the same kind.
For example, in the following figure, block and block are the same kind of Tetris block, while block and block are not the same kind of Tetris block.

Input Format
The first line contains two positive integers and , representing the size of the grid.
In the next lines, the -th line contains positive integers , representing the colors of the cells in that row.
Output Format
Output one line containing one integer, representing the answer.
5 6
1 2 3 4 4 5
1 2 3 3 4 5
1 2 2 3 4 5
1 6 6 7 7 8
6 6 7 7 8 8
7
Hint
| Subtask | Score | Special Rule | |
|---|---|---|---|
| Every Tetris block has a bounding box no larger than . | |||
| Every Tetris block is of type or , where is any positive integer. | |||
| None. |
Constraints: For all testdata, , .
Translated by ChatGPT 5