답안 #9656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
9656 2014-09-28T07:51:49 Z veckal On grid (kriii2_O) C++14
1 / 4
1000 ms 2140 KB
#include<stdio.h>
#include<string.h>

int r, c, grid[300][300], psum[300][300];
int cache[300][300];

inline int max(int a, int b) {
	return (a>b)?a:b;
}

int onGrid(int y, int x) {
	int &ret = cache[y][x];
	if (~ret) return ret;
	ret = psum[y][x];
	if (!r || !c) return ret;
	for (int i=0; i<y; ++i)
		for (int j=0; j<x; ++j)
			ret = max(ret, psum[y][x]-psum[i][x]-psum[y][j]+psum[i][j]+onGrid(i, j));
	return ret;
}

int main() {
	scanf("%d%d", &r, &c);
	for (int i=0; i<r; ++i)
		for (int j=0; j<c; ++j)
			scanf("%d", grid[i]+j);
	psum[0][0] = grid[0][0];
	for (int i=1; i<c; ++i)
		psum[0][i] = psum[0][i-1] + grid[0][i];
	for (int i=1; i<r; ++i) {
		psum[i][0] = grid[i][0];
		for (int j=1; j<c; ++j)
			psum[i][j] = psum[i][j-1] + grid[i][j];
		for (int j=0; j<c; ++j)
			psum[i][j] += psum[i-1][j];
	}
	memset(cache, -1, sizeof cache);
	printf("%d\n", onGrid(r-1, c-1));
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2140 KB Output is correct
2 Correct 0 ms 2140 KB Output is correct
3 Correct 0 ms 2140 KB Output is correct
4 Correct 0 ms 2140 KB Output is correct
5 Correct 0 ms 2140 KB Output is correct
6 Correct 0 ms 2140 KB Output is correct
7 Correct 0 ms 2140 KB Output is correct
8 Correct 0 ms 2140 KB Output is correct
9 Correct 0 ms 2140 KB Output is correct
10 Correct 0 ms 2140 KB Output is correct
11 Correct 0 ms 2140 KB Output is correct
12 Correct 0 ms 2140 KB Output is correct
13 Correct 0 ms 2140 KB Output is correct
14 Correct 0 ms 2140 KB Output is correct
15 Correct 0 ms 2140 KB Output is correct
16 Correct 0 ms 2140 KB Output is correct
17 Correct 0 ms 2140 KB Output is correct
18 Correct 0 ms 2140 KB Output is correct
19 Correct 0 ms 2140 KB Output is correct
20 Correct 0 ms 2140 KB Output is correct
21 Correct 0 ms 2140 KB Output is correct
22 Correct 0 ms 2140 KB Output is correct
23 Correct 0 ms 2140 KB Output is correct
24 Correct 0 ms 2140 KB Output is correct
25 Correct 0 ms 2140 KB Output is correct
26 Correct 0 ms 2140 KB Output is correct
27 Correct 0 ms 2140 KB Output is correct
28 Correct 0 ms 2140 KB Output is correct
29 Correct 0 ms 2140 KB Output is correct
30 Correct 0 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 2140 KB Program timed out
2 Halted 0 ms 0 KB -