#P6582. 座位调查
座位调查
Description
Youyou is sent to this computer lab to investigate. The lab is an matrix. Each cell is either O or X, where O means the cell is a seat and X means empty space. Every seat must be occupied by a student, and there is at least one seat.
To identify the cheating students, Youyou must know how many possible valid seating assignments there are in this lab. In ION 2048, contestants come from schools, and the seating must satisfy:
- The seats in the exam room are composed of several long “strips”, which makes management easier.
- No contestant can sit adjacent to a contestant from the same school, to prevent communication.
Two seats are adjacent if and only if they share a common edge.
A strip is defined as follows: except for the two endpoints which have exactly one adjacent seat, every seat has exactly two adjacent seats. Of course, a single seat also counts as a strip.
For example, the following are “strip-shaped seats”.

The following are not “strip-shaped seats”.

Note: the numbers in the cells indicate the number of adjacent seats.
Compute the total number of valid seating assignments. Since the result may be very large, output it modulo the prime . If this lab itself cannot be an ION 2048 exam lab, the answer should be .
Input Format
The first line contains three positive integers , , and .
The next lines each contain characters describing the lab. It is guaranteed that only O and X appear, and O appears at least once.
Output Format
Output one integer: the result modulo the prime .
2 3 2
OOX
XXO
4
2 3 3
XOX
XOO
12
2 3 4
XOO
XOO
0
Hint
Sample 1 Explanation
There are possible cases. Red represents students from school , and blue represents students from school :

Sample 2 Explanation
There are possible cases. Red represents students from school , blue represents students from school , and yellow represents students from school :

Sample 3 Explanation
The lab is not arranged in strips, so the answer is .
Constraints
- Subtask 1 (10 points): , .
- Subtask 2 (15 points): , .
- Subtask 3 (15 points): .
- Subtask 4 (20 points): it is guaranteed that the seats form strips, .
- Subtask 5 (20 points): it is guaranteed that the seats form strips.
- Subtask 6 (20 points): no special restrictions.
For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号