#hhkb2020e. [hhkb2020_e]Lamps
[hhkb2020_e]Lamps
Problem Statement
We have a grid with horizontal rows and vertical columns of squares, where each square is tidy or untidy.
You will now place lamps on zero or more tidy squares in this grid.
A lamp will lighten the squares in each of the four directions - up, down, left, and right - to the point just before an edge of the grid or an untidy square is reached for the first time (the untidy square will not be lighted). The lamp will also lighten the square on which it is placed.
Given are integers , , and strings of length each. If the -th character of is .
, the square at the -th row from the top and the -th column from the left is tidy; if the -th character of is #
, the square at the -th row from the top and the -th column from the left is untidy.
Let be the number of tidy squares. There are ways to place the lamps in total. Assume that, for each of these ways, the number of squares lightened by one or more lamps is computed. Find the sum of those numbers modulo .
Constraints
- is a string of length consisting of
.
and#
.
Input
Input is given from Standard Input in the following format:
Output
Print the sum, modulo , of the numbers of squares lightened by one or more lamps over the ways to place the lamps.
Sample Input 1
1 5
..#..
Sample Output 1
48
There are ways to place the lamps in total.
- In of the ways (where at least one of the -st and -nd squares from the left contains a lamp and at least one of the -th and -th squares from the left contains a lamp), squares will be lighted.
- In of the ways (where at least one of the -st and -nd squares from the left contains a lamp but none of the -th and -th squares from the left contains a lamp), squares will be lighted.
- In another of the ways (where none of the -st and -nd squares from the left contains a lamp but at least one of the -th and -th squares from the left contains a lamp), squares will be lighted.
- In of the ways (where no square contains a lamp), squares will be lighted.
The sum in question is $4 \\times 9 + 2 \\times 3 + 2 \\times 3 + 0 \\times 1 = 48$.
Sample Input 2
2 3
..#
#..
Sample Output 2
52