Submission #16512

#TimeUsernameProblemLanguageResultExecution timeMemory
16512hongjun7On grid (kriii2_O)C++98
4 / 4
79 ms2172 KiB
#include <stdio.h> #define MN 305 #define max(a, b) ((a)>(b)?(a):(b)) const int oo = 1e9; int n, m, x, c[MN][MN], d[MN][MN], f[MN][MN]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%d", &x); c[i][j] = x + c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1]; } } for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) f[i][j] = -oo; for (int j = 1; j <= m; j++) { for (int i = n; i >= 1; i--) { d[i][j] = c[i][j]; for (int k = 0; k < i; k++) d[i][j] = max(d[i][j], f[k][i] + c[i][j] - c[k][j]); for (int k = i + 1; k <= n; k++) f[i][k] = max(f[i][k], d[i][j] - c[k][j] + c[i][j]); } } printf("%d", d[n][m]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...