CF1676D.X-Sum

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid aa with nn rows and mm columns with each cell having a non-negative integer written on it.

Timur's challenge is to place a bishop on the board such that the sum of all cells attacked by the bishop is maximal. The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked. Help him find the maximal sum he can get.

蒂穆尔的祖父送给他一个棋盘来练习国际象棋技巧。这个棋盘是一个 nn 行 mm 列的网格 aa,每个格子中写有一个非负整数。

蒂穆尔的挑战是:在棋盘上放置一枚主教(Bishop),使得被该主教攻击到的所有格子上的数字之和最大。主教沿所有对角线方向攻击,且攻击距离没有限制。注意:主教所占据的格子本身也被视为被攻击。请帮助他找出所能获得的最大和。

输入格式

The first line of the input contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains the integers nn and mm (1≤n≤2001 \le n \le 200, 1≤m≤2001 \leq m \leq 200).

The following nn lines contain mm integers each, the jj-th element of the ii-th line aija_{ij} is the number written in the jj-th cell of the ii-th row (0≤aij≤106)(0\leq a_{ij} \leq 10^6)

It is guaranteed that the sum of n⋅mn\cdot m over all test cases does not exceed 4⋅1044\cdot10^4.

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤2001 \le n \le 200,1≤m≤2001 \leq m \leq 200)。

接下来的 nn 行每行包含 mm 个整数,其中第 ii 行的第 jj 个元素 aija_{ij} 表示第 ii 行第 jj 列格子中所写的数字(0≤aij≤1060\leq a_{ij} \leq 10^6)。

保证所有测试用例中 n⋅mn\cdot m 的总和不超过 4⋅1044\cdot10^4。

输出格式

For each test case output a single integer, the maximum sum over all possible placements of the bishop.

对于每个测试用例,输出一个整数,即主教所有可能放置位置中所能获得的最大和。

输入输出样例

  • 输入#1

    4
    4 4
    1 2 2 1
    2 4 2 4
    2 2 3 1
    2 4 2 4
    2 1
    1
    0
    3 3
    1 1 1
    1 1 1
    1 1 1
    3 3
    0 1 1
    1 0 1
    1 1 0

    输出#1

    20
    1
    5
    3

说明/提示

For the first test case here the best sum is achieved by the bishop being in this position:

对于第一个测试用例,主教位于以下位置时可得到最优的和:

输入解题思路,AI测评打分。不知道怎么写?

首页