#P5359. [SDOI2019] 染色
[SDOI2019] 染色
Description
Given a grid graph. Some vertices already have known colors, and the remaining vertices are not colored yet.
A valid coloring does not allow adjacent vertices to have the same color.
There are different colors in total, numbered from to .
How many valid colorings are there for the uncolored vertices?
Input Format
The first line contains two integers and , describing the size of the grid graph and the total number of colors.
Then there are two lines, each containing integers: if it is , it means the corresponding vertex is uncolored; otherwise, it must be an integer from to , meaning the vertex has already been colored with a certain color.
Output Format
Output one integer: the total number of valid colorings modulo .
3 5
1 0 1
0 0 0
172
5 7
1 0 0 0 2
0 0 3 0 0
116370
10 13
0 2 0 0 1 0 2 0 0 3
0 1 0 1 0 0 0 0 4 0
770175525
Hint
Subtask ( points): and ; there is no column with colored vertices; all colored vertices are in the first row; both the first column and the last column have a colored vertex.
Subtask ( points): and ; there is no column with colored vertices; both the first column and the last column have a colored vertex.
Subtask ( points): and ; both the first column and the last column have a colored vertex.
Subtask ( points): and .
Subtask ( points): and .
Translated by ChatGPT 5
京公网安备 11011102002149号