CF2170A.Maximum Neighborhood

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Consider an n×nn \times n grid filled with numbers as follows:

  • the first row contains integers from 11 to nn from left to right;
  • the second row contains integers from (n+1)(n+1) to 2n2n from left to right;
  • this pattern continues until the nn-th row, which contains integers from (n2−n+1)(n^2-n+1) to n2n^2 from left to right.

Let's define the cost of a cell as its value plus the sum of its neighboring cells' values. Two cells are considered neighboring if they share a side.

Your task is to calculate the maximum cost among all cells in the grid.

The grid for n=4n = 4 and the optimal answer for it. The yellow cell has the maximum possible cost; the green cells are its neighbors. The cost of the cell is 15+11+14+16=5615+11+14+16=56.

考虑一个 n×nn \times n 的网格,其中填入的数字如下:

  • 第一行从左到右依次为整数 11 到 nn;
  • 第二行从左到右依次为整数 (n+1)(n+1) 到 2n2n;
  • 依此类推,直至第 nn 行,该行从左到右依次为整数 (n2−n+1)(n^2-n+1) 到 n2n^2。

我们定义一个单元格的代价为其自身数值加上其所有相邻单元格数值之和。若两个单元格共享一条边,则称它们为相邻。

你的任务是计算该网格中所有单元格的最大代价。

当 n=4n = 4 时的网格及其最优解。黄色单元格具有可能的最大代价;绿色单元格是它的相邻单元格。该单元格的代价为 15+11+14+16=5615+11+14+16=56。

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The only line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100).

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤1001 \le n \le 100)。

输出格式

For each test case, print a single integer — the maximum cost among all cells in the grid.

对于每个测试用例,输出一个整数——网格中所有单元格的最大代价。

输入输出样例

  • 输入#1

    5
    1
    2
    3
    4
    5

    输出#1

    1
    9
    29
    56
    95

说明/提示

In the first example, there is only 11 cell with the cost 11.

In the second example, the cell with value 44 has the maximum cost: 4+2+3=94 + 2 + 3 = 9.

In the third example, the cell with value 88 has the maximum cost: 8+5+7+9=298 + 5 + 7 + 9 = 29.

In the fourth example, the cell with value 1515 has the maximum cost: 15+11+14+16=5615 + 11 + 14 + 16 = 56.

In the fifth example, the cell with value 1919 has the maximum cost: 19+14+18+20+24=9519 + 14 + 18 + 20 + 24 = 95.

在第一个例子中,只有一个单元格的成本为 11。

在第二个例子中,值为 44 的单元格具有最大成本:4+2+3=94 + 2 + 3 = 9。

在第三个例子中,值为 88 的单元格具有最大成本:8+5+7+9=298 + 5 + 7 + 9 = 29。

在第四个例子中,值为 1515 的单元格具有最大成本:15+11+14+16=5615 + 11 + 14 + 16 = 56。

在第五个例子中,值为 1919 的单元格具有最大成本:19+14+18+20+24=9519 + 14 + 18 + 20 + 24 = 95。

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

首页