# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
10111 |
2014-10-15T08:51:31 Z |
gs14004 |
On grid (kriii2_O) |
C++ |
|
0 ms |
2504 KB |
#include <cstdio>
#include <algorithm>
#include <deque>
using namespace std;
int a[301][301];
int sum[301][301];
int dp[301][301];
int r,c;
int mem[301][301];
void prep(){
scanf("%d %d",&r,&c);
for (int i=1; i<=r; i++) {
for (int j=1; j<=c; j++) {
scanf("%d",&a[i][j]);
}
}
for (int i=1; i<=r; i++) {
for (int j=1; j<=c; j++) {
sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j];
mem[i][j] = -1e9;
}
}
}
int main(){
prep();
// mem[x][y] = dp[x][l] - sum[y][l] max (x < y)
for (int i=1; i<=r; i++) {
dp[i][1] = 2* sum[i][1];
}
for (int j=2; j<=c; j++) {
for (int i=1; i<=r; i++) {
for (int k=1; k<i; k++) {
dp[i][j] = max(dp[i][j], mem[k][i] - sum[k][j]);
}
dp[i][j] += 2*sum[i][j];
}
for (int i=1; i<=r; i++) {
for (int k=i+1; k<=r; k++) {
mem[i][k] = max(mem[i][k],dp[i][j] - sum[k][j]);
}
}
}
printf("%d",dp[r][c]-sum[r][c]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2504 KB |
Output is correct |
2 |
Correct |
0 ms |
2504 KB |
Output is correct |
3 |
Correct |
0 ms |
2504 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2504 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |