Logo
(追記) (追記ここまで)

30371번 - Digit-only subrectangles 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB42150.000%

문제

There are $H$ rows and $W$ columns of square cells. Each cell has either a digit or an asterisk (‘*’). The cell at the $i$-th row from the top and the $j$-th column from the left is denoted by $(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 $S$ is a subrectangle if there are four integers $t,ドル $b,ドル $l$ and $r$ such that 1ドル \le t \le b \le H,ドル 1ドル \le l \le r \le W$ and $S = \{(i,j) \mid t \le i \le b \wedge l \le j \le 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円,353円$.

입력

The input consists of a single test case of the following format.

$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}$

The first line consists of two integers $H$ and $W,ドル which satisfy 1ドル \le H \le 2,000円$ and 1ドル \le W \le 2,000円$. Each of the following $H$ lines consists of $W$ characters. Here, $A_{i,j}$ is the character in the cell $(i,j),ドル and it is either a digit between 0ドル$ and 9ドル,ドル 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円,353円$.

제한

예제 입력 1

2 2
44
9*

예제 출력 1

346

예제 입력 2

2 3
314
28*

예제 출력 2

601

예제 입력 3

4 6
314159
2*6535
*89793
238*4*

예제 출력 3

37655

예제 입력 4

18 20
65929431919981098712
34182289733359024486
*5999742744659484782
03563591172305229098
55764088882794210744
65542986390400199274
24954674699538357427
65448003011829165060
0570520*394989799204
21113635765787241691
24382969673042349665
04571518994293776944
42950768895299998684
02191975238817773041
08629513210946362875
91583470151322043009
00337992511803056114
59396973995193492513

예제 출력 4

78257625

힌트

In Sample Input 1, there are five digit-only subrectangles as illustrated below. The sum of their scores is 4ドル^2 + 4^2 + 9^2 + (4 + 4)^2 + (4 + 9)^2 = 346$.

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

출처

Contest > ICPC Japanese Alumni Group > JAG Summer Camp > JAG Summer Camp 2023 Day 3 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /