Submission #625412

# Submission time Handle Problem Language Result Execution time Memory
625412 2022-08-10T11:28:39 Z model_code Catfish Farm (IOI22_fish) C++17
52 / 100
1000 ms 2097152 KB
#include "fish.h"

#include <climits>

#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  std::vector<std::vector<long long>> fish(N + 2, std::vector<long long>(N + 1));
  for (int i = 0; i < M; ++i) {
    fish[X[i] + 1][Y[i] + 1] = W[i];
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      fish[i][j] += fish[i][j - 1];
    }
  }

  std::vector<long long> dpInc(N + 1, -1e18), dpDec(N + 1, -1e18);
  std::vector<long long> ndpInc(N + 1), ndpDec(N + 1);
  dpInc[0] = dpDec[0] = 0;
  for (int i = 1; i <= N + 1; ++i) {
    long long pref = 0LL;
    for (int j = 0; j <= N; ++j) {
      pref = std::max(pref, dpInc[j] - fish[i - 1][j]);
      ndpInc[j] = std::max(pref + fish[i - 1][j], dpDec[0]);
    }

    long long suff = 0LL;
    for (int j = N; j >= 0; --j) {
      suff = std::max(suff, std::max(dpInc[j], dpDec[j]) + fish[i][j]);
      ndpDec[j] = suff - fish[i][j];
    }

    std::swap(dpInc, ndpInc); std::swap(dpDec, ndpDec);
  }
  return std::max(dpInc[0], dpDec[0]);
}
# Verdict Execution time Memory Grader output
1 Runtime error 982 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1034 ms 2097152 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 969 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 1064 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 976 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 1064 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 976 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 14 ms 2772 KB Output is correct
18 Correct 13 ms 2736 KB Output is correct
19 Correct 13 ms 2728 KB Output is correct
20 Correct 14 ms 2724 KB Output is correct
21 Correct 24 ms 2712 KB Output is correct
22 Correct 45 ms 4520 KB Output is correct
23 Correct 6 ms 1364 KB Output is correct
24 Correct 13 ms 2160 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 5 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 1064 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 976 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 14 ms 2772 KB Output is correct
18 Correct 13 ms 2736 KB Output is correct
19 Correct 13 ms 2728 KB Output is correct
20 Correct 14 ms 2724 KB Output is correct
21 Correct 24 ms 2712 KB Output is correct
22 Correct 45 ms 4520 KB Output is correct
23 Correct 6 ms 1364 KB Output is correct
24 Correct 13 ms 2160 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 5 ms 1236 KB Output is correct
27 Correct 93 ms 71076 KB Output is correct
28 Correct 65 ms 13552 KB Output is correct
29 Correct 185 ms 83600 KB Output is correct
30 Correct 192 ms 83624 KB Output is correct
31 Correct 179 ms 83636 KB Output is correct
32 Correct 88 ms 14660 KB Output is correct
33 Correct 194 ms 83528 KB Output is correct
34 Correct 183 ms 82900 KB Output is correct
35 Correct 121 ms 74160 KB Output is correct
36 Correct 197 ms 78164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 969 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 982 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -