Submission #8386

# Submission time Handle Problem Language Result Execution time Memory
8386 2014-09-13T16:15:17 Z cki86201 On grid (kriii2_O) C++
4 / 4
76 ms 3240 KB
#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
1 Correct 0 ms 3240 KB Output is correct
2 Correct 0 ms 3240 KB Output is correct
3 Correct 0 ms 3240 KB Output is correct
4 Correct 0 ms 3240 KB Output is correct
5 Correct 0 ms 3240 KB Output is correct
6 Correct 0 ms 3240 KB Output is correct
7 Correct 0 ms 3240 KB Output is correct
8 Correct 0 ms 3240 KB Output is correct
9 Correct 0 ms 3240 KB Output is correct
10 Correct 0 ms 3240 KB Output is correct
11 Correct 0 ms 3240 KB Output is correct
12 Correct 0 ms 3240 KB Output is correct
13 Correct 0 ms 3240 KB Output is correct
14 Correct 0 ms 3240 KB Output is correct
15 Correct 0 ms 3240 KB Output is correct
16 Correct 0 ms 3240 KB Output is correct
17 Correct 0 ms 3240 KB Output is correct
18 Correct 0 ms 3240 KB Output is correct
19 Correct 0 ms 3240 KB Output is correct
20 Correct 0 ms 3240 KB Output is correct
21 Correct 0 ms 3240 KB Output is correct
22 Correct 0 ms 3240 KB Output is correct
23 Correct 0 ms 3240 KB Output is correct
24 Correct 0 ms 3240 KB Output is correct
25 Correct 0 ms 3240 KB Output is correct
26 Correct 0 ms 3240 KB Output is correct
27 Correct 0 ms 3240 KB Output is correct
28 Correct 0 ms 3240 KB Output is correct
29 Correct 0 ms 3240 KB Output is correct
30 Correct 0 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3240 KB Output is correct
2 Correct 8 ms 3240 KB Output is correct
3 Correct 32 ms 3240 KB Output is correct
4 Correct 20 ms 3240 KB Output is correct
5 Correct 8 ms 3240 KB Output is correct
6 Correct 28 ms 3240 KB Output is correct
7 Correct 16 ms 3240 KB Output is correct
8 Correct 36 ms 3240 KB Output is correct
9 Correct 72 ms 3240 KB Output is correct
10 Correct 68 ms 3240 KB Output is correct
11 Correct 12 ms 3240 KB Output is correct
12 Correct 16 ms 3240 KB Output is correct
13 Correct 8 ms 3240 KB Output is correct
14 Correct 36 ms 3240 KB Output is correct
15 Correct 16 ms 3240 KB Output is correct
16 Correct 8 ms 3240 KB Output is correct
17 Correct 24 ms 3240 KB Output is correct
18 Correct 16 ms 3240 KB Output is correct
19 Correct 20 ms 3240 KB Output is correct
20 Correct 8 ms 3240 KB Output is correct
21 Correct 8 ms 3240 KB Output is correct
22 Correct 4 ms 3240 KB Output is correct
23 Correct 12 ms 3240 KB Output is correct
24 Correct 48 ms 3240 KB Output is correct
25 Correct 8 ms 3240 KB Output is correct
26 Correct 4 ms 3240 KB Output is correct
27 Correct 44 ms 3240 KB Output is correct
28 Correct 20 ms 3240 KB Output is correct
29 Correct 8 ms 3240 KB Output is correct
30 Correct 12 ms 3240 KB Output is correct
31 Correct 16 ms 3240 KB Output is correct
32 Correct 52 ms 3240 KB Output is correct
33 Correct 28 ms 3240 KB Output is correct
34 Correct 8 ms 3240 KB Output is correct
35 Correct 12 ms 3240 KB Output is correct
36 Correct 76 ms 3240 KB Output is correct
37 Correct 12 ms 3240 KB Output is correct
38 Correct 8 ms 3240 KB Output is correct
39 Correct 12 ms 3240 KB Output is correct
40 Correct 12 ms 3240 KB Output is correct