Submission #9554

# Submission time Handle Problem Language Result Execution time Memory
9554 2014-09-28T07:12:02 Z ainu7 On grid (kriii2_O) C++
4 / 4
80 ms 2736 KB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int sum[302][302], num[300][300];
int best[300][300];

int main()
{
  int R, C;
  cin >> R >> C;
  for (int i=0; i<R; i++) {
    for (int j=0; j<C; j++) {
    cin >> num[i][j];
//    num[i][j] = rand() % 10 - 5;
//    printf("%d ", num[i][j]);
  }
//  printf("\n");
  }
//  printf("\n");

  for (int i=0; i<R; i++) for (int j=0; j<C; j++)
    sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + num[i][j];

  // ;;
/*  for (int i=0; i<R; i++) {
    for (int j=0; j<C; j++) {
      best[i][j] = sum[i+1][j+1];
      for (int k=0; k<i; k++) for (int l=0; l<j; l++)
        best[i][j] = max(best[i][j], best[k][l] + sum[i+1][j+1] - sum[i+1][l+1] - sum[k+1][j+1] + sum[k+1][l+1]);
      printf("%d ", best[i][j]);
    }
    printf("\n");
  }
  printf("%d\n", best[R-1][C-1]);*/
  // ;;

  for (int i=0; i<C; i++) best[0][i] = sum[1][i+1];
  for (int i=1; i<R; i++) {
    for (int j=0; j<C; j++) best[i][j] = sum[i+1][j+1];
    for (int j=0; j<i; j++) {
      int last = -999999999;
      for (int k=1; k<C; k++) {
        int nxt1 = last + sum[i+1][k+1] - sum[j+1][k+1] - sum[i+1][k] + sum[j+1][k];
        best[i][k] = max(best[i][k], nxt1);

        int nxt2 = best[j][k-1] + sum[i+1][k+1] - sum[j+1][k+1] - sum[i+1][k] + sum[j+1][k];
        best[i][k] = max(best[i][k], nxt2);
//if (i == 3 && j == 2)        printf("%d %d %d %d %d\n", j, k, last, nxt1, nxt2);
        last = max(nxt1, nxt2);
      }
    }
  }
  for (int i=0; i<R; i++) {
//    for (int j=0; j<C; j++) printf("%d ", best[i][j]); printf("\n");
  }

  cout << best[R-1][C-1] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2736 KB Output is correct
2 Correct 0 ms 2736 KB Output is correct
3 Correct 0 ms 2736 KB Output is correct
4 Correct 0 ms 2736 KB Output is correct
5 Correct 0 ms 2736 KB Output is correct
6 Correct 0 ms 2736 KB Output is correct
7 Correct 0 ms 2736 KB Output is correct
8 Correct 0 ms 2736 KB Output is correct
9 Correct 0 ms 2736 KB Output is correct
10 Correct 0 ms 2736 KB Output is correct
11 Correct 0 ms 2736 KB Output is correct
12 Correct 0 ms 2736 KB Output is correct
13 Correct 0 ms 2736 KB Output is correct
14 Correct 0 ms 2736 KB Output is correct
15 Correct 0 ms 2736 KB Output is correct
16 Correct 0 ms 2736 KB Output is correct
17 Correct 0 ms 2736 KB Output is correct
18 Correct 0 ms 2736 KB Output is correct
19 Correct 0 ms 2736 KB Output is correct
20 Correct 0 ms 2736 KB Output is correct
21 Correct 0 ms 2736 KB Output is correct
22 Correct 0 ms 2736 KB Output is correct
23 Correct 0 ms 2736 KB Output is correct
24 Correct 0 ms 2736 KB Output is correct
25 Correct 0 ms 2736 KB Output is correct
26 Correct 0 ms 2736 KB Output is correct
27 Correct 0 ms 2736 KB Output is correct
28 Correct 0 ms 2736 KB Output is correct
29 Correct 0 ms 2736 KB Output is correct
30 Correct 0 ms 2736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2736 KB Output is correct
2 Correct 12 ms 2736 KB Output is correct
3 Correct 28 ms 2736 KB Output is correct
4 Correct 24 ms 2736 KB Output is correct
5 Correct 12 ms 2736 KB Output is correct
6 Correct 32 ms 2736 KB Output is correct
7 Correct 20 ms 2736 KB Output is correct
8 Correct 52 ms 2736 KB Output is correct
9 Correct 76 ms 2736 KB Output is correct
10 Correct 72 ms 2736 KB Output is correct
11 Correct 28 ms 2736 KB Output is correct
12 Correct 28 ms 2736 KB Output is correct
13 Correct 12 ms 2736 KB Output is correct
14 Correct 68 ms 2736 KB Output is correct
15 Correct 24 ms 2736 KB Output is correct
16 Correct 16 ms 2736 KB Output is correct
17 Correct 44 ms 2736 KB Output is correct
18 Correct 40 ms 2736 KB Output is correct
19 Correct 32 ms 2736 KB Output is correct
20 Correct 16 ms 2736 KB Output is correct
21 Correct 16 ms 2736 KB Output is correct
22 Correct 12 ms 2736 KB Output is correct
23 Correct 16 ms 2736 KB Output is correct
24 Correct 60 ms 2736 KB Output is correct
25 Correct 8 ms 2736 KB Output is correct
26 Correct 8 ms 2736 KB Output is correct
27 Correct 56 ms 2736 KB Output is correct
28 Correct 28 ms 2736 KB Output is correct
29 Correct 16 ms 2736 KB Output is correct
30 Correct 20 ms 2736 KB Output is correct
31 Correct 32 ms 2736 KB Output is correct
32 Correct 80 ms 2736 KB Output is correct
33 Correct 44 ms 2736 KB Output is correct
34 Correct 16 ms 2736 KB Output is correct
35 Correct 20 ms 2736 KB Output is correct
36 Correct 76 ms 2736 KB Output is correct
37 Correct 20 ms 2736 KB Output is correct
38 Correct 20 ms 2736 KB Output is correct
39 Correct 16 ms 2736 KB Output is correct
40 Correct 12 ms 2736 KB Output is correct