#P15348. [TOIP 2025] 同色樓梯和雙色樓梯
[TOIP 2025] 同色樓梯和雙色樓梯
Problem Description
In an grid, each cell has exactly one color, and we use uppercase English letters to represent each color.
A “stair” means: several consecutive vertical segments, where the bottom positions of these segments (the columns they are in) must be the same, and the height increases by step by step from left to right. Note that the height and width of a stair shape must be equal.
A “monochrome stair” means: all cells covered by the stair have the same color.
A “two-color stair” means: the cells covered by the stair contain exactly two colors.
In the example figure below, the blue, yellow, and green shapes are “monochrome stairs” with width (height) , , and , respectively. Note that stairs may overlap. For example, next to the blue stair there is another stair. Also, any large stair must contain smaller stairs. For example, in the figure below, the width stair contains stairs of width . The width stair contains stairs of width and stairs of width .
:::align{center}
:::
In the following example figure, all “two-color stairs” are marked.
:::align{center}
:::
Your task is to compute, for each possible width (height), how many monochrome stairs or two-color stairs there are.
Input Format
$$\begin{aligned} &m \; n \\ &a_{1,1} a_{1,2} a_{1,3} \cdots a_{1,n} \\ &a_{2,1} a_{2,2} a_{2,3} \cdots a_{2,n} \\ &a_{3,1} a_{3,2} a_{3,3} \cdots a_{3,n} \\ &\vdots \\ &a_{m,1} a_{m,2} a_{m,3} \cdots a_{m,n} \\ &q \end{aligned}$$- and represent the height and width of the region, respectively.
- represents the color of the region.
- If , query the number of monochrome stairs. If , query the number of two-color stairs.
Output Format
$$\begin{aligned} &k \\ &s_1 \; s_2 \; s_3 \; \cdots \; s_k \end{aligned}$$- is a non-negative integer, representing the maximum width (height) among all monochrome stairs (two-color stairs).
- Each is a non-negative integer, representing the number of monochrome stairs (two-color stairs) with width (height) .
- If , output an empty line on the second line.
6 8
BCCDDAAA
CCCBBBAB
DDDAAAAB
EBBEAAAA
EBBAAAAA
BBBBABCD
1
4
48 12 4 1
3 3
BCC
CCC
DDD
1
2
9 2
3 3
BCC
CCC
DDD
2
3
0 2 1
Hint
Constraints
- .
- .
- are uppercase English letters.
- and are integers.
- .
Scoring
This problem has five subtasks, with the constraints as follows. Each subtask may contain one or more testdata, and you will receive the score for that subtask only if all testdata in the subtask are answered correctly.
| Subtask | Score | Additional Input Constraints |
|---|---|---|
| 1 | 5 | , all are the same. |
| 2 | 9 | , , . |
| 3 | 22 | , . |
| 4 | 33 | . |
| 5 | 31 | . |
Translated by ChatGPT 5