#P15908. [TOPC 2024] Disbursement on Quarantine Policy
[TOPC 2024] Disbursement on Quarantine Policy
Description
:::epigraph[“Quarantine Policy,” 2023 ICPC Taoyuan Regional Contest, Problem D]
The 2019 novel coronavirus, COVID-19, can be transmitted between humans through water droplets and close contact. The transmission is especially easy and fast in relatively crowded or confined spaces, such as airplanes or trains. If someone is infected with COVID-19, then passengers occupying the adjacent seats will be infected easily.
:::
There is a train with rows, and there are seats per row. All seats are occupied. For some passengers, we know they are being infected with COVID-19 or not. However, for other passengers, we are not sure about their status, and we assume each of them has chance being infected with COVID-19, independent from each other.
All infected passengers need to be quarantined for days. All passengers that are not infected, but edge-adjacent to any infected passenger, need to be quarantined for days. All passengers that are not infected, not edge-adjacent to any infected passenger, but corner-adjacent to any infected passenger, need to be quarantined for days.
The passengers need to stay in the hotel during quarantine. According to the regulations, the government needs to pay for the hotel. As an accountant of the government, you are asked to evaluate the expected total number of days the passengers need to be quarantined, which indicates the expected total cost on paying for the hotel.
For example, suppose , , , , . The third passenger in the third row is infected, and we don’t know whether the second passenger in the first row is infected or not. Other 14 passengers are not infected.
If the second passenger in the first row is infected, then the total number of days of quarantine is 91:
7 15 7 0
3 7 7 3
0 7 15 7
0 3 7 3
If that passenger is not infected, then the total number of days of quarantine is 55:
0 0 0 0
0 3 7 3
0 7 15 7
0 3 7 3
So the expected total number of days of quarantine is .
Input Format
The first line contains five integers , , , and . The following lines contain characters each. The -th character of the -th line represents the passenger occupying the -th seat of the -th row. Each character is one of ‘V’, ‘.’, or ‘?’. ‘V’ means an infected passenger, ‘.’ means a not infected passenger, and ‘?’ means a passenger that has chance being infected.
Output Format
The expected total number of days the passengers need to be quarantined, modulo . It can be proved that the answer can be represented by a rational number where is not a multiple of . Then you need to print modulo , where means the multiplicative inverse of modulo .
Note: If , then is the multiplicative inverse of modulo .
4 4 15 7 3
.?..
....
..V.
....
73
22111
??
??
750000009
京公网安备 11011102002149号