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

20632번 - Route Calculator Returns 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB119777.778%

문제

You have a grid with $H$ rows and $W$ columns. Each cell contains one of the following 11 characters: an addition operator '+', a multiplication operator '*', or a digit between 1 and 9.

There are paths from the top-left cell to the bottom-right cell by moving right or down $H+W-2$ times. Let us define the value of a path by the evaluation result of the mathematical expression you can obtain by concatenating all the characters contained in the cells on the path in order. Your task is to compute the sum of values of any possible paths. Since the sum can be large, find it modulo $M$.

It is guaranteed the top-left cell and the bottom-right cell contain digits. Moreover, if two cells share an edge, at least one of them contains a digit. In other words, each expression you can obtain from a path is mathematically valid.

입력

The first line of the input consists of three integers $H,ドル $W$ and $M$ (1ドル \le H,W \le 2000,ドル 2ドル \le M \le 10^9$). The following $H$ lines represent the characters on the grid. $a_{i,j}$ represents the character contained in the cell at the $i$-th row and $j$-th column. Each $a_{i,j}$ is either '+', '*', or a digit between 1 and 9. $a_{1,1}$ and $a_{H,W}$ are both digits. If two cells share an edge, at least one of them contain a digit.

출력

Print the sum of values of all possible paths modulo $M$.

제한

예제 입력 1

2 3 1000
3*1
+27

예제 출력 1

162

예제 입력 2

4 4 3000000
24+7
*23*
9+48
*123

예제 출력 2

2159570

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 5: JAG Summer+ Opening Contest G번

Contest > ICPC Japanese Alumni Group > JAG Summer Camp > JAG Summer Camp 2019 Day 1 G번

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

출처

대학교 대회

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

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