# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
9823 |
2014-09-28T12:24:10 Z |
veckal |
On grid (kriii2_O) |
C++14 |
|
40 ms |
107612 KB |
#include<stdio.h>
#include<string.h>
int r, c, grid[300][300], psum[300][300];
int cache[300][300], reCache[300][300][300];
inline int max(int a, int b) {
return (a>b)?a:b;
}
int reverseGrid(int, int, int);
int onGrid(int y, int x) {
int &ret = cache[y][x];
if (~ret) return ret;
ret = psum[y][x];
if (!r || !c) return ret;
for (int h=0; h<y; ++h)
ret = max(ret, reverseGrid(y, x-1, h)+psum[y][x]-psum[h][x]-psum[y][x-1]+psum[h][x-1]);
return ret;
}
int reverseGrid(int y, int x, int h) {
int &ret = reCache[y][x][h];
if (~ret) return ret;
ret = psum[h][x];
if (x == 0) return ret;
return ret = max(ret, reverseGrid(y, x-1, h)+psum[y][x]-psum[h][x]-psum[y][x-1]+psum[h][x-1]);
}
int main() {
scanf("%d%d", &r, &c);
for (int i=0; i<r; ++i)
for (int j=0; j<c; ++j)
scanf("%d", grid[i]+j);
psum[0][0] = grid[0][0];
for (int i=1; i<c; ++i)
psum[0][i] = psum[0][i-1] + grid[0][i];
for (int i=1; i<r; ++i) {
psum[i][0] = grid[i][0] + psum[i-1][0];
for (int j=1; j<c; ++j)
psum[i][j] = psum[i][j-1] + psum[i-1][j] + grid[i][j] - psum[i-1][j-1];
}
memset(cache, -1, sizeof cache);
memset(reCache, -1, sizeof reCache);
printf("%d\n", onGrid(r-1, c-1));
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
107612 KB |
Output is correct |
2 |
Incorrect |
40 ms |
107612 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |