#abc225g. G - X
G - X
Score : points
问题描述
我们有一个包含 行和 列的网格。每个格子中包含一个整数。位于第 行(从上到下数)和第 列(从左到右数)的格子 中包含整数 。
Takahashi 将从这 个格子中选择零个或多个,并在每个选中的格子上画一个 X。X 由一条连接左上角和右下角的线段,以及一条连接右上角和左下角的线段组成。
让我们定义 Takahashi 的得分是(所有画了 X 的格子中整数之和)(画出这些 X 所需的最小线段数)。
注意,Takahashi 可以一次性在对角相邻的格子上画 X。
例如,他可以用三条线段同时在格子 和 上画 X:
- 连接 左上角与 右下角的线段,
- 连接 右上角与 左下角的线段,
- 连接 右上角与 左下角的线段。
找出 Takahashi 最大可能的得分。请注意,未被选中的格子上不应画任何内容。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a grid with horizontal rows and vertical columns. Each square contains an integer. The square at the -th row from the top and -th column from the left contains the integer .
Takahashi will choose zero or more from the squares and draw an X on each of them. An X is composed of a segment connecting the top-left and bottom-right corners, and a segment connecting the top-right and bottom-left corners.
Let us define Takahashi's score as the sum of integers contained in the squares on which X is drawnthe minimum number of segments needed to draw the X's.
Here, Takahashi can draw X's on diagonally adjacent squares at once.
For example, he can draw X's on the squares and with three segments:
- a segment connecting the top-left corner of and the bottom-right corner of ,
- a segment connecting the top-right corner of and the bottom-left corner of ,
- a segment connecting the top-right corner of and the bottom-left corner of .
Find Takahashi's maximum possible score. Note that nothing should be drawn on unchosen squares.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print Takahashi's maximum possible score.
Sample Input 1
2 2 2
2 10
8 3
Sample Output 1
12
If he chooses the squares and , he can draw X's on them with three segments:
- a segment connecting the top-left corner of and the bottom-right corner of ,
- a segment connecting the top-left corner of and the bottom-right corner of ,
- a segment connecting the top-right corner of and the bottom-left corner of .
Thus, Takahashi's score here will be .
There is no way to mark squares that achieves a strictly higher score, so the answer is .
Sample Input 2
3 3 100
1 1 1
1 1 1
1 1 1
Sample Output 2
0
It is best to mark no squares.
Sample Input 3
8 9 970861213
1313462 943495812 203775264 839015475 115668311 14701110 819458175 827176922 236492592
843915104 786367010 344840288 618248834 824858165 549189141 120648070 805825275 933750119
709330492 38579914 890555497 75314343 238373458 854061807 637519536 53226153 627677130
671706386 380984116 221773266 787763728 639374738 298691145 359138139 183373508 524415106
716502263 150803008 390520954 913021901 553285119 876389099 952721235 46809105 635239775
355621458 511843148 117663063 37274476 891025941 832254337 346436418 783134705 488516288
383723241 322408013 948364423 409068145 120813872 697127655 968230339 988041557 222591780
712959990 233114128 210373172 798667159 568746366 579461421 923556823 777007925 422249456
Sample Output 3
9785518299
update @ 2024/3/10 09:54:09