Submission #9313

# Submission time Handle Problem Language Result Execution time Memory
9313 2014-09-28T05:32:26 Z lemonsqueeze On grid (kriii2_O) C++
4 / 4
464 ms 216972 KB
#include <stdio.h>
#include <algorithm>
using namespace std;

int n, m;
long long a[301][301];

long long s[301][301];
long long d[301][301];
long long w[301][301][302];

int main ()
{
	scanf ("%d%d", &n, &m);
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
		scanf ("%lld", &a[i][j]);
		s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
	}

	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			d[i][j] = s[i][j];

			if (j>=2) {
				for (int a=1; a<i; a++) {
					if (d[i][j] < w[a][i][j] + s[i][j] - s[a][j])
						d[i][j] = w[a][i][j] + s[i][j] - s[a][j];
				}

				for (int a=1; a<i; a++)
					w[a][i][j+1] = max (w[a][i][j], d[a][j] + s[a][j] - s[i][j]);
			}

			else {
				for (int a=1; a<i; a++)
					w[a][i][j+1] = d[a][j] + s[a][j] - s[i][j];
			}
		}
	}

	printf ("%lld\n", d[n][m]);

	return 0;
}

/*

2 2
1 -1
-1 1

5 5
4 -2 3 -4 2
-2 1 1 4 -2
-3 1 -1 2 5
2 -4 2 3 5
1 -4 4 -1 -2

 */
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216972 KB Output is correct
2 Correct 0 ms 216972 KB Output is correct
3 Correct 0 ms 216972 KB Output is correct
4 Correct 0 ms 216972 KB Output is correct
5 Correct 0 ms 216972 KB Output is correct
6 Correct 0 ms 216972 KB Output is correct
7 Correct 0 ms 216972 KB Output is correct
8 Correct 0 ms 216972 KB Output is correct
9 Correct 0 ms 216972 KB Output is correct
10 Correct 0 ms 216972 KB Output is correct
11 Correct 0 ms 216972 KB Output is correct
12 Correct 0 ms 216972 KB Output is correct
13 Correct 0 ms 216972 KB Output is correct
14 Correct 0 ms 216972 KB Output is correct
15 Correct 0 ms 216972 KB Output is correct
16 Correct 0 ms 216972 KB Output is correct
17 Correct 0 ms 216972 KB Output is correct
18 Correct 0 ms 216972 KB Output is correct
19 Correct 0 ms 216972 KB Output is correct
20 Correct 0 ms 216972 KB Output is correct
21 Correct 0 ms 216972 KB Output is correct
22 Correct 0 ms 216972 KB Output is correct
23 Correct 0 ms 216972 KB Output is correct
24 Correct 0 ms 216972 KB Output is correct
25 Correct 0 ms 216972 KB Output is correct
26 Correct 0 ms 216972 KB Output is correct
27 Correct 0 ms 216972 KB Output is correct
28 Correct 0 ms 216972 KB Output is correct
29 Correct 0 ms 216972 KB Output is correct
30 Correct 0 ms 216972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 216972 KB Output is correct
2 Correct 28 ms 216972 KB Output is correct
3 Correct 196 ms 216972 KB Output is correct
4 Correct 88 ms 216972 KB Output is correct
5 Correct 8 ms 216972 KB Output is correct
6 Correct 96 ms 216972 KB Output is correct
7 Correct 48 ms 216972 KB Output is correct
8 Correct 224 ms 216972 KB Output is correct
9 Correct 444 ms 216972 KB Output is correct
10 Correct 444 ms 216972 KB Output is correct
11 Correct 48 ms 216972 KB Output is correct
12 Correct 116 ms 216972 KB Output is correct
13 Correct 36 ms 216972 KB Output is correct
14 Correct 324 ms 216972 KB Output is correct
15 Correct 80 ms 216972 KB Output is correct
16 Correct 36 ms 216972 KB Output is correct
17 Correct 136 ms 216972 KB Output is correct
18 Correct 108 ms 216972 KB Output is correct
19 Correct 192 ms 216972 KB Output is correct
20 Correct 12 ms 216972 KB Output is correct
21 Correct 16 ms 216972 KB Output is correct
22 Correct 12 ms 216972 KB Output is correct
23 Correct 28 ms 216972 KB Output is correct
24 Correct 388 ms 216972 KB Output is correct
25 Correct 4 ms 216972 KB Output is correct
26 Correct 16 ms 216972 KB Output is correct
27 Correct 312 ms 216972 KB Output is correct
28 Correct 116 ms 216972 KB Output is correct
29 Correct 28 ms 216972 KB Output is correct
30 Correct 24 ms 216972 KB Output is correct
31 Correct 64 ms 216972 KB Output is correct
32 Correct 404 ms 216972 KB Output is correct
33 Correct 144 ms 216972 KB Output is correct
34 Correct 16 ms 216972 KB Output is correct
35 Correct 68 ms 216972 KB Output is correct
36 Correct 464 ms 216972 KB Output is correct
37 Correct 32 ms 216972 KB Output is correct
38 Correct 28 ms 216972 KB Output is correct
39 Correct 32 ms 216972 KB Output is correct
40 Correct 32 ms 216972 KB Output is correct