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<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
//O(R^2 * C)
int d[303][303];
int p[303][303];
int b[2][303][606], t;
#define Get(a,b,c,d) (p[c][d]-p[a-1][d]-p[c][b-1]+p[a-1][b-1])
int main(){
int r,c,i,j;
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)for(j=1;j<=c;j++)scanf("%d",p[i]+j);
for(i=1;i<=r;i++)for(j=1;j<=c;j++)p[i][j] += p[i][j-1] + p[i-1][j] - p[i-1][j-1];
for(i=1;i<=r;i++)for(j=1;j<=c;j++)d[i][j] = p[i][j];
for(i=2;i<=r;i++){
for(j=i-1;j;j--){
int now = 0, mx;
d[i][2] = max(d[i][2], mx = d[j][1] + Get(j+1,2,i,2));
for(int k=3;k<=c;k++){
mx += Get(j+1,k,i,k);
now += d[j][k-1] - d[j][k-2] - Get(j+1,k-1,i,k-1);
if(now > 0)mx += now, now = 0;
d[i][k] = max(d[i][k], mx);
}
}
}
printf("%d",d[r][c]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |