#P15723. [JAG 2023 Summer Camp #3] Digit-only subrectangles

[JAG 2023 Summer Camp #3] Digit-only subrectangles

题目描述

There are HH rows and WW columns of square cells. Each cell has either a digit or an asterisk ('*'). The cell at the ii-th row from the top and the jj-th column from the left is denoted by (i,j)(i, j).

In this problem we consider subrectangles, each of which is the set of cells which forms a rectangle. More precisely, a set of cells SS is a subrectangle if there are four integers tt, bb, ll and rr such that 1tbH1 \leq t \leq b \leq H, 1lrW1 \leq l \leq r \leq W 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 998,244,353998,244,353.

输入格式

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 HH and WW, which satisfy 1H2,0001 \leq H \leq 2,000 and 1W2,0001 \leq W \leq 2,000. Each of the following HH lines consists of WW characters. Here, Ai,jA_{i,j} is the character in the cell (i,j)(i, j), and it is either a digit between 00 and 99, 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 998,244,353998,244,353.

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 42+42+92+(4+4)2+(4+9)2=3464^2 + 4^2 + 9^2 + (4 + 4)^2 + (4 + 9)^2 = 346.

:::align{center}

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