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>
using namespace std;
//O(R^2 * C^2)
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=0;i<=r;i++)for(j=0;j<=c;j++)d[i][j] = (i||j) * (-1e9);
for(i=2;i<=r+c;i++,t^=1){
for(j=max(1,i-c);j<=min(i-1,r);j++){
d[j][i-j] = d[j-1][i-j-1] + Get(j,i-j,j,i-j), b[t][j][i] = j;
for(int k=i-1;k>=2;k--){
for(int l=(j==max(1,i-c)?max(1,k-c):b[!t][j-1][k]);l<=(j==min(i-1,r)?min(k-1,r):b[!t][j][k]);++l){
int a = d[l-1][k-l-1] + Get(l,k-l,j,i-j);
if(d[j][i-j] < a)d[j][i-j] = a, b[t][j][k] = l;
}
}
}
}
printf("%d",d[r][c]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |