#P15723. [JAG 2023 Summer Camp #3] Digit-only subrectangles
[JAG 2023 Summer Camp #3] Digit-only subrectangles
题目描述
There are rows and columns of square cells. Each cell has either a digit or an asterisk ('*'). The cell at the -th row from the top and the -th column from the left is denoted by .
In this problem we consider subrectangles, each of which is the set of cells which forms a rectangle. More precisely, a set of cells is a subrectangle if there are four integers , , and such that , and $S = \{(i, j) \mid t \leq i \leq b \land l \leq j \leq r\}$. A subrectangle is digit-only if every cell in the subrectangle has a digit. The score of a digit-only subrectangle is defined as the square of the sum of digits in cells in the subrectangle.
Your task is to calculate the sum of scores of all digit-only subrectangles. Since the answer may be large, output it modulo .
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} &H \ W \\ &A_{1,1} A_{1,2} \cdots A_{1,W} \\ &A_{2,1} A_{2,2} \cdots A_{2,W} \\ &\vdots \\ &A_{H,1} A_{H,2} \cdots A_{H,W} \end{aligned} $$The first line consists of two integers and , which satisfy and . Each of the following lines consists of characters. Here, is the character in the cell , and it is either a digit between and , inclusive, or an asterisk ('*'). It is guaranteed that there is at least one digit-only subrectangle.
输出格式
Output in a line the sum of scores of all digit-only subrectangles modulo .
2 2
44
9*
346
2 3
314
28*
601
4 6
314159
2*6535
*89793
238*4*
37655
18 20
65929431919981098712
34182289733359024486
*5999742744659484782
03563591172305229098
55764088882794210744
65542986390400199274
24954674699538357427
65448003011829165060
0570520*394989799204
21113635765787241691
24382969673042349665
04571518994293776944
42950768895299998684
02191975238817773041
08629513210946362875
91583470151322043009
00337992511803056114
59396973995193492513
78257625
提示
In Sample Input 1, there are five digit-only subrectangles as illustrated below. The sum of their scores is .
:::align{center}

Figure F.1. Digit-only subrectangles in Sample Input 1 :::