#P7626. [COCI 2011/2012 #1] MATRIX

    ID: 8568 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>模拟2011枚举COCI(克罗地亚)

[COCI 2011/2012 #1] MATRIX

Problem Description

Given an N×NN \times N matrix, find the square submatrix (i.e., with equal height and width) that has the maximum beauty value.

Define the beauty value of a matrix as follows: let AA be the sum of the numbers on the main diagonal of this matrix, and let BB be the sum of the numbers on the other diagonal. Then the beauty value is ABA - B.

Input Format

The first line contains a positive integer NN.

The next NN lines each contain NN integers, describing the matrix.

Output Format

Output one integer on a single line, the maximum beauty value.

2
1 -2
4 5
4
3
1 2 3
4 5 6
7 8 9
0
3
-3 4 5
7 9 -2
1 0 -6
5

Hint

Constraints

For 100%100\% of the testdata, 1N4001 \le N \le 400, and each matrix element [103,103]\in [-10^3,10^3].

Notes

The scoring of this problem follows the original COCI settings. The full score is 8080.

This problem is translated from COCI2011-2012 CONTEST #1 T2 MATRIX.

Translated by ChatGPT 5