#jag2017summerday3e. [jag2017summer_day3_e]Route Calculator
[jag2017summer_day3_e]Route Calculator
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
You have a grid with rows and columns. is even. We denote the cell at the -th row from the top and the -th column from the left by . In any cell , an integer between and is written if is even, and either +
or *
is written if is odd.
You can get a mathematical expression by moving right or down times from to 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 to . If the maximum value is or less, print the value. Otherwise, print .
Input
The input consists of a single test case in the format below.
The first line consists of two integers and (). It is guaranteed that is even. The following lines represent the characters on the grid. represents the character written in the cell . In any cell , an integer between and is written if is even, and either +
or *
is written if is odd.
Output
Print the answer in one line.
Sample Input 1
3 3
1+2
+9*
1*5
Output for Sample Input 1
46
The maximum value is obtained by passing through the following cells: , , , , .
Sample Input 2
1 31
9*9*9*9*9*9*9*9*9*9*9*9*9*9*9*9
Output for Sample Input 2
-1
You can obtain , but it's too large.
Sample Input 3
5 5
2+2+1
+1+1+
1+2+2
+1+1+
1+1+2
Output for Sample Input 3
10
Sample Input 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
Output for Sample Input 4
86408