

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
縦 行、横 列からなるマス目があり、それぞれのマスは散らかっているか散らかっていないかのどちらかです。
今からあなたはこのマス目のうち 個以上の散らかっていないマスに照明を置きます。
照明は置かれたマスの上下左右の 方向に、マス目の端もしくは最初に散らかっているマスにぶつかる直前まで照らします (散らかっているマスは照らされません)。照明は、置かれたマス自身も照らします。
整数 と 個の長さ の文字列 が与えられます。 の 文字目が .
のとき、上から 行目、左から
列目のマスは散らかっていません。 の 文字目が #
のとき、上から 行目、左から
列目のマスは散らかっています。
散らかっていないマスの個数を 個だとすると、照明の置き方は全部で 通りあります。 この 通りそれぞれについて、 個以上の照明によって照らされるマスの個数を計算したときの総和を で割ったあまりを求めてください。
制約
- は
.
と#
のみからなる長さ の文字列
入力
入力は以下の形式で標準入力から与えられる。
出力
通りそれぞれについて、 個以上の照明によって照らされるマスの個数を計算したときの総和を で割ったあまりを出力せよ。
入力例 1Copy
1 5 ..#..
出力例 1Copy
48
全部で照明の置き方は 通りあります。
- このうち 通り (左から 番目か 番目の少なくとも一方に照明が置かれている、かつ左から 番目か 番目の少なくとも一方に照明が置かれている) では、 マスが照らされます。
- このうち 通り (左から 番目か 番目の少なくとも一方に照明が置かれている、かつ左から 番目と 番目のどちらにも照明が置かれていない) では、 マスが照らされます。
- このうち 通り (左から 番目か 番目の少なくとも一方に照明が置かれている、かつ左から 番目と 番目のどちらにも照明が置かれていない) では、 マスが照らされます。
- このうち 通り (照明が つも置かれていない) では、 マスが照らされます。
求める総和は となります。
入力例 2Copy
2 3 ..# #..
出力例 2Copy
52
Score : points
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 1Copy
1 5 ..#..
Sample Output 1Copy
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 .
Sample Input 2Copy
2 3 ..# #..
Sample Output 2Copy
52