-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10827.cpp
More file actions
28 lines (22 loc) · 723 Bytes
/
10827.cpp
File metadata and controls
28 lines (22 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <limits.h>
using namespace std;
int sum[160][160], n, tc;
int main() {
cin >> tc;
while (tc--) {
cin >> n;
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
cin >> sum[i][j];
sum[i+n][j] = sum[i][j+n] = sum[i+n][j+n] = sum[i][j];
}
for (int i = 1; i <= 2*n; i++) for (int j = 1; j <= 2*n; j++)
sum[i][j] += (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]);
int m = INT_MIN;
for (int i0 = 0; i0 <= n; i0++) for (int j0 = 0; j0 <= n; j0++)
for (int i1 = i0 + 1; i1 <= i0+n; i1++) for (int j1 = j0 + 1; j1 <= j0+n; j1++)
m = max(m, sum[i1][j1] - sum[i0][j1] - sum[i1][j0] + sum[i0][j0]);
cout << m << endl;
}
return 0;
}