E - Lamps Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

HH 行、横 WW 列からなるマス目があり、それぞれのマスは散らかっているか散らかっていないかのどちらかです。

今からあなたはこのマス目のうち 00 個以上の散らかっていないマスに照明を置きます。

照明は置かれたマスの上下左右の 44 方向に、マス目の端もしくは最初に散らかっているマスにぶつかる直前まで照らします (散らかっているマスは照らされません)。照明は、置かれたマス自身も照らします。

整数 H,WH, WHH 個の長さ WW の文字列 SiS_i が与えられます。 SiS_ijj 文字目が . のとき、上から ii 行目、左から jj 列目のマスは散らかっていません。SiS_ijj 文字目が # のとき、上から ii 行目、左から jj 列目のマスは散らかっています。

散らかっていないマスの個数を KK 個だとすると、照明の置き方は全部で 2K2^K 通りあります。 この 2K2^K 通りそれぞれについて、11 個以上の照明によって照らされるマスの個数を計算したときの総和を 1,000,000,0071,000,000,007 で割ったあまりを求めてください。

制約

  • 1H20001 \leq H \leq 2000
  • 1W20001 \leq W \leq 2000
  • SiS_i.# のみからなる長さ WW の文字列

入力

入力は以下の形式で標準入力から与えられる。

HH WW
S1S_1
::
SHS_H

出力

2K2^K 通りそれぞれについて、11 個以上の照明によって照らされるマスの個数を計算したときの総和を 1,000,000,0071,000,000,007 で割ったあまりを出力せよ。


入力例 1Copy

Copy
1 5
..#..

出力例 1Copy

Copy
48

全部で照明の置き方は 1616 通りあります。

  • このうち 99 通り (左から 11 番目か 22 番目の少なくとも一方に照明が置かれている、かつ左から 44 番目か 55 番目の少なくとも一方に照明が置かれている) では、44 マスが照らされます。
  • このうち 33 通り (左から 11 番目か 22 番目の少なくとも一方に照明が置かれている、かつ左から 44 番目と 55 番目のどちらにも照明が置かれていない) では、22 マスが照らされます。
  • このうち 33 通り (左から 44 番目か 55 番目の少なくとも一方に照明が置かれている、かつ左から 11 番目と 22 番目のどちらにも照明が置かれていない) では、22 マスが照らされます。
  • このうち 11 通り (照明が 11 つも置かれていない) では、00 マスが照らされます。

求める総和は 4×9+2×3+2×3+0×1=484 \times 9 + 2 \times 3 + 2 \times 3 + 0 \times 1 = 48 となります。


入力例 2Copy

Copy
2 3
..#
#..

出力例 2Copy

Copy
52

Score : 500500 points

Problem Statement

We have a grid with HH horizontal rows and WW 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 HH, WW, and HH strings SiS_i of length WW each. If the jj-th character of SiS_i is ., the square at the ii-th row from the top and the jj-th column from the left is tidy; if the jj-th character of SiS_i is #, the square at the ii-th row from the top and the jj-th column from the left is untidy.

Let KK be the number of tidy squares. There are 2K2^K ways to place the lamps in total. Assume that, for each of these 2K2^K ways, the number of squares lightened by one or more lamps is computed. Find the sum of those numbers modulo 1,000,000,0071,000,000,007.

Constraints

  • 1H20001 \leq H \leq 2000
  • 1W20001 \leq W \leq 2000
  • SiS_i is a string of length WW consisting of . and #.

Input

Input is given from Standard Input in the following format:

HH WW
S1S_1
::
SHS_H

Output

Print the sum, modulo 1,000,000,0071,000,000,007, of the numbers of squares lightened by one or more lamps over the 2K2^K ways to place the lamps.


Sample Input 1Copy

Copy
1 5
..#..

Sample Output 1Copy

Copy
48

There are 1616 ways to place the lamps in total.

  • In 99 of the ways (where at least one of the 11-st and 22-nd squares from the left contains a lamp and at least one of the 44-th and 55-th squares from the left contains a lamp), 44 squares will be lighted.
  • In 33 of the ways (where at least one of the 11-st and 22-nd squares from the left contains a lamp but none of the 44-th and 55-th squares from the left contains a lamp), 22 squares will be lighted.
  • In another 33 of the ways (where none of the 11-st and 22-nd squares from the left contains a lamp but at least one of the 44-th and 55-th squares from the left contains a lamp), 22 squares will be lighted.
  • In 11 of the ways (where no square contains a lamp), 00 squares will be lighted.

The sum in question is 4×9+2×3+2×3+0×1=484 \times 9 + 2 \times 3 + 2 \times 3 + 0 \times 1 = 48.


Sample Input 2Copy

Copy
2 3
..#
#..

Sample Output 2Copy

Copy
52


2025-03-29 (Sat)
10:50:53 +00:00