No.2509 Beam Shateki
タグ : / 解いたユーザー数 91
作問者 : 👑
PCTprobability
amentorimaru
Problem Statement
There is a grid with $H+2$ rows and $W+2$ columns. The rows of the grid are numbered $0, 1, ..., H+1$ from top to bottom and the columns are numbered $0, 1, ..., W+1$ from left to right, and the cell in row $i$ and column $j$ is cell $(i,j)$.
An outer cell is defined as a cell satisfying any of the following conditions. A cell other than the outer cells is defined as an inner cell.
- It is located in row $0$
- It is located in row $H+1$
- It is located in column $0$
- It is located in column $W+1$
Each inner cell has $1$ box with a positive integer written on it. The number written on the box placed in cell $(i,j)$ is $A_{i,j}$, and before any operation, no box has been destroyed.
You may perform the following beam-firing operation on this grid at most $2$ times.
Beam-firing operation
- Choose $1$ outer cell and make it the current position.
- Choose each of $d_x,d_y$ independently from $-1,0,1$. However, $d_x=d_y=0$ is not allowed.
- Unless the operation has ended, repeat the following actions in order.
- When the current position is cell $(x, y)$, if cell $(x + d_x, y + d_y)$ does not exist or cell $(x + d_x, y + d_y)$ is an outer cell, end the operation.
- When the current position is cell $(x, y)$, update the current position to cell $(x + d_x, y + d_y)$.
- If the box placed at the current position has not already been destroyed, destroy it.
Find the maximum possible sum of the numbers written on the destroyed boxes after at most $2$ operations have ended.
Input
$H\ W \\
A_{1,1}\ A_{1,2}\ \dots\ A_{1,W}\\
A_{2,1}\ A_{2,2}\ \dots\ A_{2,W}\\
\vdots \\
A_{H,1}\ A_{H,2}\ \dots\ A_{H,W}
$
Constraints
- $1 \le H,\ W \le 100$
- $1 \le A_{i,j} \le 10000\ (1 \le i \le H,\ 1 \le j \le W)$
Output
Output the answer.
Sample
Sample 1
Input
4 3 2 3 6 2 5 7 3 2 1 1 1 3
Output
28
In the $1$st operation, fire a beam downward ( $(d_x,d_y) = (1,0)$ ) from cell $(0,2)$, destroying the boxes with $3,\ 5,\ 2,\ 1$ written on them.
In the $2$nd operation, fire a beam downward ( $(d_x,d_y) = (1,0)$ ) from cell $(0,3)$, destroying the boxes with $6,\ 7,\ 1,\ 3$ written on them.
In the end, the sum of the numbers written on the destroyed boxes is $3+5+2+1+6+7+1+3 = 28$.
The sum of the numbers written on the destroyed boxes cannot be made $29$ or more, so output $28$.
Sample 2
Input
3 3 3 1 1 1 3 1 3 3 9
Output
21
It is optimal to fire a beam toward the lower right ( $(d_x,d_y) = (1,1)$ ) from cell $(0,0)$ in the $1$st operation, and to the right ( $(d_x,d_y) = (0,1)$ ) from cell $(3,0)$ in the $2$nd operation. Note that in the $2$nd operation, a box that has already been destroyed cannot be destroyed again.
Sample 3
Input
1 1 10000
Output
10000
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。