Submission #625418

# Submission time Handle Problem Language Result Execution time Memory
625418 2022-08-10T11:29:06 Z model_code Catfish Farm (IOI22_fish) C++17
100 / 100
263 ms 33704 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<std::pair<int, long long>>> fish(N + 2);
  for (int i = 0; i < M; ++i) {
    fish[X[i] + 1].emplace_back(Y[i], W[i]);
  }

  fish[0] = {{-1, 0LL}};
  for (int i = 1; i <= N; ++i) {
    fish[i].emplace_back(-1, 0LL);
    std::sort(fish[i].begin(), fish[i].end());
    for (int j = 1; j < static_cast<int>(fish[i].size()); ++j) {
      fish[i][j].second += fish[i][j - 1].second;
    }
  }
  fish[N + 1] = {{-1, 0LL}};

  auto getRowWeight = [&](int row, int col) {
    return (upper_bound(fish[row].begin(), fish[row].end(), std::make_pair(col, LLONG_MAX)) - 1)->second;
  };

  std::vector<std::vector<int>> indices(N + 2);
  indices[0] = {-1};
  for (int i = 1; i <= N; ++i) {
    for (std::pair<int, int> f : fish[i - 1]) {
      indices[i].push_back(f.first);
    }
    for (std::pair<int, int> f : fish[i + 1]) {
      indices[i].push_back(f.first);
    }
    std::sort(indices[i].begin(), indices[i].end());
    indices[i].erase(std::unique(indices[i].begin(), indices[i].end()), indices[i].end());
  }
  indices[N + 1] = {-1};

  std::vector<long long> dpInc = {0LL}, dpDec = {0LL};
  for (int i = 1; i <= N + 1; ++i) {
    std::vector<long long> ndpInc(indices[i].size());
    long long pref = 0LL;
    int pidx = 0;
    for (int j = 0; j < static_cast<int>(indices[i].size()); ++j) {
      int col = indices[i][j];
      while (pidx < static_cast<int>(indices[i - 1].size()) && indices[i - 1][pidx] <= col) {
        pref = std::max(pref, dpInc[pidx] - getRowWeight(i - 1, indices[i - 1][pidx]));
        ++pidx;
      }
      ndpInc[j] = std::max(pref + getRowWeight(i - 1, col), dpDec[0]);
    }

    std::vector<long long> ndpDec(indices[i].size());
    long long suff = 0;
    int sidx = indices[i - 1].size();
    for (int j = static_cast<int>(indices[i].size()) - 1; j >= 0; --j) {
      int col = indices[i][j];
      while (sidx > 0 && indices[i - 1][sidx - 1] >= col) {
        --sidx;
        suff = std::max(suff, std::max(dpInc[sidx], dpDec[sidx]) + getRowWeight(i, indices[i - 1][sidx]));
      }
      ndpDec[j] = suff - getRowWeight(i, col);
    }

    std::swap(dpInc, ndpInc);
    std::swap(dpDec, ndpDec);
  }
  return std::max(dpInc[0], dpDec[0]);
}
# Verdict Execution time Memory Grader output
1 Correct 87 ms 16184 KB Output is correct
2 Correct 95 ms 18844 KB Output is correct
3 Correct 25 ms 11220 KB Output is correct
4 Correct 36 ms 11180 KB Output is correct
5 Correct 205 ms 33704 KB Output is correct
6 Correct 197 ms 28880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 135 ms 22780 KB Output is correct
3 Correct 147 ms 23344 KB Output is correct
4 Correct 61 ms 14880 KB Output is correct
5 Correct 74 ms 17056 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 25 ms 11128 KB Output is correct
11 Correct 25 ms 11220 KB Output is correct
12 Correct 70 ms 15180 KB Output is correct
13 Correct 80 ms 17424 KB Output is correct
14 Correct 69 ms 15060 KB Output is correct
15 Correct 86 ms 16696 KB Output is correct
16 Correct 68 ms 15012 KB Output is correct
17 Correct 75 ms 16680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 11220 KB Output is correct
2 Correct 24 ms 11256 KB Output is correct
3 Correct 49 ms 12328 KB Output is correct
4 Correct 41 ms 12756 KB Output is correct
5 Correct 71 ms 15552 KB Output is correct
6 Correct 74 ms 15680 KB Output is correct
7 Correct 76 ms 15648 KB Output is correct
8 Correct 77 ms 15672 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 0 ms 216 KB Output is correct
6 Correct 1 ms 220 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 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 0 ms 216 KB Output is correct
6 Correct 1 ms 220 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 23 ms 3276 KB Output is correct
18 Correct 22 ms 4068 KB Output is correct
19 Correct 20 ms 3988 KB Output is correct
20 Correct 19 ms 4004 KB Output is correct
21 Correct 22 ms 3924 KB Output is correct
22 Correct 45 ms 7592 KB Output is correct
23 Correct 7 ms 980 KB Output is correct
24 Correct 18 ms 2388 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 5 ms 852 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 0 ms 216 KB Output is correct
6 Correct 1 ms 220 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 23 ms 3276 KB Output is correct
18 Correct 22 ms 4068 KB Output is correct
19 Correct 20 ms 3988 KB Output is correct
20 Correct 19 ms 4004 KB Output is correct
21 Correct 22 ms 3924 KB Output is correct
22 Correct 45 ms 7592 KB Output is correct
23 Correct 7 ms 980 KB Output is correct
24 Correct 18 ms 2388 KB Output is correct
25 Correct 1 ms 300 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 124 ms 17272 KB Output is correct
29 Correct 191 ms 18120 KB Output is correct
30 Correct 187 ms 17108 KB Output is correct
31 Correct 187 ms 17152 KB Output is correct
32 Correct 142 ms 20172 KB Output is correct
33 Correct 183 ms 17172 KB Output is correct
34 Correct 184 ms 17104 KB Output is correct
35 Correct 68 ms 8968 KB Output is correct
36 Correct 200 ms 19520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 11220 KB Output is correct
2 Correct 24 ms 11256 KB Output is correct
3 Correct 49 ms 12328 KB Output is correct
4 Correct 41 ms 12756 KB Output is correct
5 Correct 71 ms 15552 KB Output is correct
6 Correct 74 ms 15680 KB Output is correct
7 Correct 76 ms 15648 KB Output is correct
8 Correct 77 ms 15672 KB Output is correct
9 Correct 86 ms 15680 KB Output is correct
10 Correct 60 ms 11556 KB Output is correct
11 Correct 125 ms 23160 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 26 ms 11192 KB Output is correct
19 Correct 26 ms 11208 KB Output is correct
20 Correct 25 ms 11224 KB Output is correct
21 Correct 26 ms 11212 KB Output is correct
22 Correct 90 ms 16412 KB Output is correct
23 Correct 153 ms 23132 KB Output is correct
24 Correct 132 ms 24832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 16184 KB Output is correct
2 Correct 95 ms 18844 KB Output is correct
3 Correct 25 ms 11220 KB Output is correct
4 Correct 36 ms 11180 KB Output is correct
5 Correct 205 ms 33704 KB Output is correct
6 Correct 197 ms 28880 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 135 ms 22780 KB Output is correct
9 Correct 147 ms 23344 KB Output is correct
10 Correct 61 ms 14880 KB Output is correct
11 Correct 74 ms 17056 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 25 ms 11128 KB Output is correct
17 Correct 25 ms 11220 KB Output is correct
18 Correct 70 ms 15180 KB Output is correct
19 Correct 80 ms 17424 KB Output is correct
20 Correct 69 ms 15060 KB Output is correct
21 Correct 86 ms 16696 KB Output is correct
22 Correct 68 ms 15012 KB Output is correct
23 Correct 75 ms 16680 KB Output is correct
24 Correct 24 ms 11220 KB Output is correct
25 Correct 24 ms 11256 KB Output is correct
26 Correct 49 ms 12328 KB Output is correct
27 Correct 41 ms 12756 KB Output is correct
28 Correct 71 ms 15552 KB Output is correct
29 Correct 74 ms 15680 KB Output is correct
30 Correct 76 ms 15648 KB Output is correct
31 Correct 77 ms 15672 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 216 KB Output is correct
37 Correct 1 ms 220 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 288 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 2 ms 344 KB Output is correct
48 Correct 23 ms 3276 KB Output is correct
49 Correct 22 ms 4068 KB Output is correct
50 Correct 20 ms 3988 KB Output is correct
51 Correct 19 ms 4004 KB Output is correct
52 Correct 22 ms 3924 KB Output is correct
53 Correct 45 ms 7592 KB Output is correct
54 Correct 7 ms 980 KB Output is correct
55 Correct 18 ms 2388 KB Output is correct
56 Correct 1 ms 300 KB Output is correct
57 Correct 5 ms 852 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 124 ms 17272 KB Output is correct
60 Correct 191 ms 18120 KB Output is correct
61 Correct 187 ms 17108 KB Output is correct
62 Correct 187 ms 17152 KB Output is correct
63 Correct 142 ms 20172 KB Output is correct
64 Correct 183 ms 17172 KB Output is correct
65 Correct 184 ms 17104 KB Output is correct
66 Correct 68 ms 8968 KB Output is correct
67 Correct 200 ms 19520 KB Output is correct
68 Correct 86 ms 15680 KB Output is correct
69 Correct 60 ms 11556 KB Output is correct
70 Correct 125 ms 23160 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 26 ms 11192 KB Output is correct
78 Correct 26 ms 11208 KB Output is correct
79 Correct 25 ms 11224 KB Output is correct
80 Correct 26 ms 11212 KB Output is correct
81 Correct 90 ms 16412 KB Output is correct
82 Correct 153 ms 23132 KB Output is correct
83 Correct 132 ms 24832 KB Output is correct
84 Correct 263 ms 29148 KB Output is correct
85 Correct 257 ms 29864 KB Output is correct
86 Correct 197 ms 27512 KB Output is correct
87 Correct 219 ms 28076 KB Output is correct
88 Correct 0 ms 284 KB Output is correct
89 Correct 216 ms 28824 KB Output is correct
90 Correct 196 ms 28312 KB Output is correct
91 Correct 166 ms 28912 KB Output is correct