Submission #10101

# Submission time Handle Problem Language Result Execution time Memory
10101 2014-10-15T05:54:10 Z gs14004 On grid (kriii2_O) C++
1 / 4
1000 ms 2148 KB
#include <cstdio>
#include <algorithm>
using namespace std;

int a[301][301];
int sum[301][301];
int dp[301][301];
int r,c;

int recsum(int x1, int x2, int y1, int y2){
    return sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];
}

int main(){
    scanf("%d %d",&r,&c);
    for (int i=1; i<=r; i++) {
        for (int j=1; j<=c; j++) {
            scanf("%d",&a[i][j]);
        }
    }
    for (int i=1; i<=r; i++) {
        for (int j=1; j<=c; j++) {
            sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j];
        }
    }
    for (int i=1; i<=r; i++) {
        dp[i][1] = sum[i][1];
    }
    for (int i=1; i<=c; i++) {
        dp[1][i] = sum[1][i];
    }
    for (int i=2; i<=r; i++) {
        for (int j=2; j<=c; j++) {
            dp[i][j] = sum[i][j];
            for (int k=2; k<=i; k++) {
                for (int l=2; l<=j; l++) {
                    dp[i][j] = max(dp[i][j],dp[k-1][l-1] + recsum(k,i,l,j));
                }
            }
        }
    }
    printf("%d",dp[r][c]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2148 KB Output is correct
2 Correct 0 ms 2148 KB Output is correct
3 Correct 0 ms 2148 KB Output is correct
4 Correct 0 ms 2148 KB Output is correct
5 Correct 0 ms 2148 KB Output is correct
6 Correct 0 ms 2148 KB Output is correct
7 Correct 0 ms 2148 KB Output is correct
8 Correct 0 ms 2148 KB Output is correct
9 Correct 0 ms 2148 KB Output is correct
10 Correct 0 ms 2148 KB Output is correct
11 Correct 0 ms 2148 KB Output is correct
12 Correct 0 ms 2148 KB Output is correct
13 Correct 0 ms 2148 KB Output is correct
14 Correct 0 ms 2148 KB Output is correct
15 Correct 0 ms 2148 KB Output is correct
16 Correct 0 ms 2148 KB Output is correct
17 Correct 0 ms 2148 KB Output is correct
18 Correct 0 ms 2148 KB Output is correct
19 Correct 0 ms 2148 KB Output is correct
20 Correct 0 ms 2148 KB Output is correct
21 Correct 0 ms 2148 KB Output is correct
22 Correct 0 ms 2148 KB Output is correct
23 Correct 0 ms 2148 KB Output is correct
24 Correct 0 ms 2148 KB Output is correct
25 Correct 0 ms 2148 KB Output is correct
26 Correct 0 ms 2148 KB Output is correct
27 Correct 0 ms 2148 KB Output is correct
28 Correct 0 ms 2148 KB Output is correct
29 Correct 0 ms 2148 KB Output is correct
30 Correct 0 ms 2148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 2148 KB Output is correct
2 Correct 136 ms 2148 KB Output is correct
3 Correct 596 ms 2148 KB Output is correct
4 Correct 332 ms 2148 KB Output is correct
5 Correct 156 ms 2148 KB Output is correct
6 Execution timed out 1000 ms 2148 KB Program timed out
7 Halted 0 ms 0 KB -