Disbursement on Quarantine Policy

시간 제한2초메모리 제한1024 MB

요약
일부 좌석의 감염 여부가 확정되고 나머지는 1/2 확률로 감염될 때, 전체 격자의 기대 격리 일수를 구한다.
난이도

보통10점 중 6점

유형
확률, 수학, 행렬, 구현
정답자
아직 제출이 없습니다

문제

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.


—“Quarantine Policy,” 2023 ICPC Taoyuan Regional Contest, Problem D

There is a train with nn rows, and there are mm 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 12\frac{1}{2} chance being infected with COVID-19, independent from each other.

All infected passengers need to be quarantined for d_0d\_0 days. All passengers that are not infected, but edge-adjacent to any infected passenger, need to be quarantined for d_1d\_1 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 d_2d\_2 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 n=4n = 4, m=4m = 4, d_0=15d\_0 = 15, d_1=7d\_1 = 7, d_2=3d\_2 = 3. 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 1414 passengers are not infected.

If the second passenger in the first row is infected, then the total number of days of quarantine is 9191:

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 5555:

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 91+552=73\frac{91+55}{ 2} = 73.

입력

The first line contains five integers nn, mm, d_0d\_0, d_1d\_1 and d_2d\_2. The following nn lines contain mm characters each. The jj-th character of the ii-th line represents the passenger occupying the jj-th seat of the ii-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 12\frac{1}{ 2} chance being infected.

출력

The expected total number of days the passengers need to be quarantined, modulo 109+710^9 + 7. It can be proved that the answer can be represented by a rational number pq\frac{p}{ q} where qq is not a multiple of 109+710^9 + 7. Then you need to print p×q−1p \times q^{-1} modulo 109+710^9 + 7, where q−1q^{-1} means the multiplicative inverse of qq modulo 109+710^9 + 7.

Note: If x×q≡1 mod 109+7x \times q \equiv 1 \bmod 10^9 + 7, then xx is the multiplicative inverse of qq modulo 109+710^9 + 7.

제한

  • 1≤n≤1001 ≤ n ≤ 100
  • 1≤m≤1001 ≤ m ≤ 100
  • 0≤d_2≤d_1≤d_0≤1000 ≤ d\_2 ≤ d\_1 ≤ d\_0 ≤ 100

예제2

  1. 예제 1

    입력
    4 4 15 7 3
    .?..
    ....
    ..V.
    ....
    
    예상 출력
    73
    
  2. 예제 2

    입력
    2 2 1 1 1
    ??
    ??
    
    예상 출력
    750000009