This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <iostream>
#include <cstring>
#include <tuple>
#include <cassert>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i=0; i < n; ++i)
int n, m;
int a[305][305];
long long S[305][305];
long long V[305][305];
long long C[305][305];
long long M[305][305][305];
long long go() {
memset(C, 0, sizeof(C));
memset(M, 0, sizeof(M));
memset(V, 0, sizeof(V));
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= m; ++ j) {
S[i][j] = a[i][j] + S[i-1][j] + S[i][j-1] - S[i-1][j-1];
}
}
const long long INF = 1LL << 50;
for(int i = 1; i <= n; ++ i) {
V[i][0] = -INF;
C[i][0] = -INF;
}
for(int j = 1; j <= m; ++ j) {
V[0][j] = -INF;
C[0][j] = -INF;
}
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= m; ++ j) {
V[i][j] = -987987;
for(int k = 0; k < i; ++ k) {
for(int l = 0; l < j; ++ l) {
V[i][j] = max(V[i][j], V[k][l] - S[i][l] - S[k][j] + S[k][l] + S[i][j]);
}
}
}
}
return V[n][m];
}
int main() {
while(cin >> n >> m && n && m ) {
for(int i = 1; i <= n; ++ i) {
for(int j=1; j<=m; ++j) {
cin >> a[i][j];
}
}
cout << go() << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |