#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
using namespace std;
int r, c;
int map[310][310];
int dyn[310][310];
int psum[310][310];
int E[310][310][310];
void process() {
int i, j, k;
for (i=1;i<=r;i++) for (j=1;j<=c;j++) psum[i][j] = psum[i-1][j]+psum[i][j-1]-psum[i-1][j-1]+map[i][j];
for (i=0;i<=r;i++) for (j=0;j<=c;j++) for (k=0;k<=r;k++) E[i][j][k] = -1000000000;
for (i=1;i<=r;i++) for (j=1;j<=c;j++) {
if (j!=1) for (k=1;k<i;k++) E[i][j][k] = max(E[i][j-1][k],dyn[k][j-1]+psum[k][j-1]-psum[i][j-1]);
dyn[i][j] = psum[i][j];
if (i!=1&&j!=1) for (k=1;k<i;k++) dyn[i][j] = max(dyn[i][j],E[i][j][k]+psum[i][j]-psum[k][j]);
}
printf("%d\n",dyn[r][c]);
}
void input() {
int i, j;
scanf("%d %d",&r,&c);
for (i=1;i<=r;i++) for (j=1;j<=c;j++) scanf("%d",&map[i][j]);
}
int main() {
input();
process();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
118580 KB |
Output is correct |
2 |
Correct |
0 ms |
118580 KB |
Output is correct |
3 |
Correct |
0 ms |
118580 KB |
Output is correct |
4 |
Correct |
0 ms |
118580 KB |
Output is correct |
5 |
Correct |
0 ms |
118580 KB |
Output is correct |
6 |
Correct |
0 ms |
118580 KB |
Output is correct |
7 |
Correct |
0 ms |
118580 KB |
Output is correct |
8 |
Correct |
0 ms |
118580 KB |
Output is correct |
9 |
Correct |
0 ms |
118580 KB |
Output is correct |
10 |
Correct |
0 ms |
118580 KB |
Output is correct |
11 |
Correct |
0 ms |
118580 KB |
Output is correct |
12 |
Correct |
0 ms |
118580 KB |
Output is correct |
13 |
Correct |
0 ms |
118580 KB |
Output is correct |
14 |
Correct |
0 ms |
118580 KB |
Output is correct |
15 |
Correct |
0 ms |
118580 KB |
Output is correct |
16 |
Correct |
0 ms |
118580 KB |
Output is correct |
17 |
Correct |
0 ms |
118580 KB |
Output is correct |
18 |
Correct |
0 ms |
118580 KB |
Output is correct |
19 |
Correct |
0 ms |
118580 KB |
Output is correct |
20 |
Correct |
0 ms |
118580 KB |
Output is correct |
21 |
Correct |
0 ms |
118580 KB |
Output is correct |
22 |
Correct |
0 ms |
118580 KB |
Output is correct |
23 |
Correct |
0 ms |
118580 KB |
Output is correct |
24 |
Correct |
0 ms |
118580 KB |
Output is correct |
25 |
Correct |
0 ms |
118580 KB |
Output is correct |
26 |
Correct |
0 ms |
118580 KB |
Output is correct |
27 |
Correct |
0 ms |
118580 KB |
Output is correct |
28 |
Correct |
0 ms |
118580 KB |
Output is correct |
29 |
Correct |
0 ms |
118580 KB |
Output is correct |
30 |
Correct |
0 ms |
118580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
118580 KB |
Output is correct |
2 |
Correct |
4 ms |
118580 KB |
Output is correct |
3 |
Correct |
28 ms |
118580 KB |
Output is correct |
4 |
Correct |
14 ms |
118580 KB |
Output is correct |
5 |
Correct |
7 ms |
118580 KB |
Output is correct |
6 |
Correct |
29 ms |
118580 KB |
Output is correct |
7 |
Correct |
17 ms |
118580 KB |
Output is correct |
8 |
Correct |
41 ms |
118580 KB |
Output is correct |
9 |
Correct |
63 ms |
118580 KB |
Output is correct |
10 |
Correct |
75 ms |
118580 KB |
Output is correct |
11 |
Correct |
17 ms |
118580 KB |
Output is correct |
12 |
Correct |
14 ms |
118580 KB |
Output is correct |
13 |
Correct |
21 ms |
118580 KB |
Output is correct |
14 |
Correct |
60 ms |
118580 KB |
Output is correct |
15 |
Correct |
13 ms |
118580 KB |
Output is correct |
16 |
Correct |
11 ms |
118580 KB |
Output is correct |
17 |
Correct |
26 ms |
118580 KB |
Output is correct |
18 |
Correct |
42 ms |
118580 KB |
Output is correct |
19 |
Correct |
32 ms |
118580 KB |
Output is correct |
20 |
Correct |
12 ms |
118580 KB |
Output is correct |
21 |
Correct |
8 ms |
118580 KB |
Output is correct |
22 |
Correct |
8 ms |
118580 KB |
Output is correct |
23 |
Correct |
19 ms |
118580 KB |
Output is correct |
24 |
Correct |
76 ms |
118580 KB |
Output is correct |
25 |
Correct |
12 ms |
118580 KB |
Output is correct |
26 |
Correct |
5 ms |
118580 KB |
Output is correct |
27 |
Correct |
53 ms |
118580 KB |
Output is correct |
28 |
Correct |
30 ms |
118580 KB |
Output is correct |
29 |
Correct |
11 ms |
118580 KB |
Output is correct |
30 |
Correct |
18 ms |
118580 KB |
Output is correct |
31 |
Correct |
25 ms |
118580 KB |
Output is correct |
32 |
Correct |
76 ms |
118580 KB |
Output is correct |
33 |
Correct |
44 ms |
118580 KB |
Output is correct |
34 |
Correct |
16 ms |
118580 KB |
Output is correct |
35 |
Correct |
18 ms |
118580 KB |
Output is correct |
36 |
Correct |
81 ms |
118580 KB |
Output is correct |
37 |
Correct |
24 ms |
118580 KB |
Output is correct |
38 |
Correct |
10 ms |
118580 KB |
Output is correct |
39 |
Correct |
10 ms |
118580 KB |
Output is correct |
40 |
Correct |
8 ms |
118580 KB |
Output is correct |