题目描述
Problem Description
Consider a board divided into $ h $ by $ w $ squares, resulting in $ hw $ squares in total. Each square contains a single-digit number from 0 to 9 or a . (dot). The coordinates of the squares are assigned such that the top-left square is $(1,\ 1)$, the top-right is $(1,\ w)$, the bottom-left is $(h,\ 1)$, and the bottom-right is $(h,\ w)$.
Repeat the following steps until there is only one integer left on the board:
- Randomly select one pair of squares with the maximum Manhattan distance among all pairs of squares containing integers. (The Manhattan distance between two squares with coordinates $(a,\ b)$ and $(c,\ d)$ is calculated as $|a\ -\ c|\ +\ |b\ -\ d|$.)
- In the selected pair, overwrite the larger number's square with the sum of the two numbers, and overwrite the smaller number's square with a
.. If the original numbers are equal, overwrite one of them with their sum and the other with a..
After the above procedure, find the maximum possible integer that can remain on the board.
Input Format
The input is given in the following format:
$ h $ $ w $ $ b_1 $ $ ... $ $ b_h $
- The first line contains integers $ h $ and $ w $ ($1\ \leq\ h,\ w\ \leq\ 100$), representing the height and width of the board.
- The following $ h $ lines contain the board information.
- $ b_i $ represents the information of the $ i $-th row from the top, which is a string of length $ w $ containing single-digit integers from
0to9or.. - It is guaranteed that the board contains at least one integer.
Output Format
Output the maximum possible integer that can remain on the board in one line.
End with a newline and do not include any extra characters or blank lines.
Sample Input and Output
Sample Input #1
2 3
12.
.5.
Sample Output #1
8
Sample Input #2
5 5
..3.9
.1..6
2.3.4
7..11
....8
Sample Output #2
45
Notes/Hints
None
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分