#P7160. 「dWoi R1」Sixth Monokuma's Son
「dWoi R1」Sixth Monokuma's Son
Background
The problem first defines a matrix ring as follows: given a matrix , which is initially all white, select a submatrix in it and paint it black, then select a submatrix inside and paint it white, and a matrix ring is formed. Note that a matrix ring must have selected parts on all four sides (top, bottom, left, and right), and the whole matrix ring is not a rectangular matrix.
Assume + is black and - is white. The following is a matrix ring:
---+++++--
---++--+--
---+++++--
---+++++--
----------
The following are not matrix rings:
------- ------
---+++- --+++-
---+-+- --+++-
------- --+++-
Therefore, a matrix ring has four sides: top, bottom, left, and right. For each direction, the number of painted-black layers is the thickness in that direction. For example, in the first valid figure, the thicknesses of the top and right sides are , and the thicknesses of the left and bottom sides are .
Note that a complete matrix is not a matrix ring.
Next is the actual background story:
After Saihara got the clue "Gokuhara found some small bugs", he took action immediately. First, he used Iruma's relic, the thing that looked like a flamethrower, to suck in some air. Then, he planned to use Kibo's mechanical eye to inspect it.
Problem Description
Kibo's mechanical eye can scan an area. At row and column , it detects an abnormality value of .
Because Kibo is severely tortured by external forces, he can only lock onto one matrix ring to inspect. Kibo wants to ask you for help: he wants you to lock onto a matrix ring such that the sum of abnormality values of all positions in the matrix ring is maximized, the thicknesses of the top and bottom sides are , and the top row is the first row of the whole area, while the bottom row is the last row of the whole area. As for the left and right thicknesses, Kibo has no further constraints.
Input Format
The first line contains two integers , representing the size of the whole area.
Then lines follow, each containing integers , representing the abnormality value at each position.
Output Format
Output one integer in one line, representing the answer.
If it is impossible to choose a matrix ring that satisfies the requirements, output .
4 4
3 -4 2 -2
-5 3 -4 2
-1 3 -4 0
3 -3 3 4
8
1 2
11 45
-1
7 7
10 10 10 -100 11 11 11
10 10 10 -100 11 -100 11
10 10 10 -100 11 -100 11
10 10 10 -100 11 -100 11
10 10 10 -100 11 -100 11
10 10 10 -100 11 -100 11
10 10 10 -100 11 11 11
176
Hint
Sample Explanation
Explanation for Sample 1:
You can choose a matrix ring of the following form (but in fact the two solutions are the same, because the sum of all numbers in the first column is ):
++++ -+++
++-+ -+-+
++-+ -+-+
++++ -+++
Here, + means selected, and - means not selected.
For Sample 3, the provider is
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (5 pts): or .
- Subtask 2 (5 pts): .
- Subtask 3 (40 pts): .
- Subtask 4 (50 pts): No special constraints.
For of the testdata, , , .
Translated by ChatGPT 5