Route Calculator

시간 제한2초메모리 제한512 MB

요약
격자에서 오른쪽과 아래로만 이동하며 숫자와 +, * 기호를 이어 붙여 수식을 만들고, 그 값을 최대로 만든다.
난이도

보통10점 중 6점

유형
동적 계획법, 행렬, 구현, 수학
정답자
아직 제출이 없습니다

문제

You have a grid with HH rows and WW columns. H+WH+W is even. We denote the cell at the ii-th row from the top and the jj-th column from the left by (i,j)(i, j). In any cell (i,j)(i, j), an integer between 11 and 99 is written if i+ji+j is even, and either + or * is written if i+ji+j is odd.

You can get a mathematical expression by moving right or down H+W−2H+W-2 times from (1,1)(1,1) to (H,W)(H,W) and concatenating all the characters written in the cells you passed in order. Your task is to maximize the calculated value of the resulting mathematical expression by choosing an arbitrary path from (1,1)(1, 1) to (H,W)(H, W). If the maximum value is 101510^{15} or less, print the value. Otherwise, print −1-1.

입력

The input consists of a single test case in the format below.

$H$ $W$ $a_{1,1}$ $\cdots$ $a_{1,W}$ $\ldots$ $a_{H,1}$ $\cdots$ $a_{H,W}$

The first line consists of two integers HH and WW (1≤H,W≤501 \le H,W \le 50). It is guaranteed that H+WH+W is even. The following HH lines represent the characters on the grid. a_i,ja\_{i,j} represents the character written in the cell (i,j)(i,j). In any cell (i,j)(i, j), an integer between 11 and 99 is written if i+ji+j is even, and either + or * is written if i+ji+j is odd.

출력

Print the answer in one line.

예제4

  1. 예제 1

    입력
    3 3
    1+2
    +9*
    1*5
    
    예상 출력
    46
    
  2. 예제 2

    입력
    1 31
    9*9*9*9*9*9*9*9*9*9*9*9*9*9*9*9
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    5 5
    2+2+1
    +1+1+
    1+2+2
    +1+1+
    1+1+2
    
    예상 출력
    10
    
  4. 예제 4

    입력
    9 7
    8+9*4*8
    *5*2+3+
    1*3*2*2
    *5*1+9+
    1+2*2*2
    *3*6*2*
    7*7+6*5
    *5+7*2+
    3+3*6+8
    
    예상 출력
    86408