#P10042. [CCPC 2023 北京市赛] 三染色
[CCPC 2023 北京市赛] 三染色
Problem Description
I have a palette with rows and columns, forming cells, and each cell must contain a flower. There are possible colors of flowers, denoted by .
Flowers watch the surrounding flowers and want to become like other flowers. At a moment, if a flower of color has at least one adjacent flower (up, down, left, or right) whose color is , then at the next moment this flower will become color ; otherwise, its color at the next moment is still . Here colors are considered .
For an initial placement of flowers on the palette, if after a finite number of moments all flowers become the same color, then we call this placement good.
It is not hard to see that for a good placement, each flower has an earliest moment such that after this moment its color never changes again. We call this moment the flower's stabilization time. We start counting from moment , so if a flower never changes color, then its stabilization time is .
Now I have already placed flowers in some cells of the palette, and some cells are empty. I want to know: how many ways are there to place flowers in the remaining cells such that the resulting placement is good? Also, among these good placements, what is the sum of the stabilization times of the flower in the cell at row , column ?
You only need to output these two results modulo .
Input Format
The first line contains two positive integers (, ).
Then follow lines, each containing integers. The -th integer in the -th line is , describing the state of the corresponding cell. Here means there is a flower and its color, and means there is no flower.
Output Format
Output one line with two integers: the number of good placements, and the sum of the stabilization times of the flower in the top-left cell.
2 2
1 0
3 2
1 2
5 5
3 3 3 3 2
2 3 3 3 1
1 3 3 3 3
3 3 3 3 3
3 3 3 3 3
50830224 170059345
Hint
[Sample Explanation 1]
Only when the unknown cells are filled with flowers of color will the process end, and after two moments all flowers' colors become . At this time, the flower in the top-left cell changes to color and will not change anymore, so its stabilization time is .
Translated by ChatGPT 5