Submission #627037

# Submission time Handle Problem Language Result Execution time Memory
627037 2022-08-12T05:19:59 Z lunchbox Catfish Farm (IOI22_fish) C++17
100 / 100
502 ms 49020 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

const ll INF = 1e18;

ll max_weights(int n, int m, vi x, vi y, vi w) {
  vector<vector<pair<int, ll>>> s(n + 1);
  for (int i = 0; i < m; i++)
    s[x[i] + 1].push_back({y[i] + 1, w[i]});
  for (int i = 0; i <= n; i++) {
    s[i].push_back({0, 0});
    s[i].push_back({n + 1, 0});
    sort(s[i].begin(), s[i].end());
    ll x = 0;
    for (auto &[j, w] : s[i]) {
      x += w;
      w = x;
    }
  }
  vector<vi> p(n + 1);
  auto pos = [&](int i, int k) {
    return lower_bound(p[i].begin(), p[i].end(), k) - p[i].begin();
  };
  auto sum = [&](int i, int k) {
    return s[i][upper_bound(s[i].begin(), s[i].end(), make_pair(k, (ll) 0)) - s[i].begin() - 1].second;
  };
  vector<vector<array<ll, 2>>> f(n + 1);
  p[0].push_back(0);
  f[0].assign(1, {-INF, -INF});
  f[0][0][0] = f[0][0][1] = 0;
  for (int i = 1; i <= n; i++) {
    for (auto [j, w] : s[i - 1])
      p[i].push_back(j);
    for (auto [j, w] : s[i])
      p[i].push_back(j);
    sort(p[i].begin(), p[i].end());
    p[i].erase(unique(p[i].begin(), p[i].end()), p[i].end());
    int m = p[i].size();
    f[i].assign(m + 1, {-INF, -INF});
    vector<ll> a(m + 1, -INF), b(m + 1, -INF), c(m + 1, -INF), d(m + 1, -INF);
    for (int k = 0; k < (int) p[i - 1].size(); k++) {
      a[pos(i, p[i - 1][k])] = max(f[i - 1][k][0], f[i - 1][k][1]) + sum(i, p[i - 1][k]);
      d[pos(i, p[i - 1][k])] = f[i - 1][k][1] - sum(i - 1, p[i - 1][k]);
    }
    if (i > 1)
      for (int k = 0; k < (int) p[i - 2].size(); k++) {
        b[pos(i, p[i - 2][k])] = max(f[i - 2][k][0], f[i - 2][k][1]);
        c[pos(i, p[i - 2][k])] = max(f[i - 2][k][0], f[i - 2][k][1]) + sum(i - 1, p[i - 2][k]);
      }
    for (int k = m - 1; k >= 0; k--) {
      a[k] = max(a[k], a[k + 1]);
      c[k] = max(c[k], c[k + 1]);
    }
    for (int k = 0; k < m; k++) {
      b[k + 1] = max(b[k + 1], b[k]);
      d[k + 1] = max(d[k + 1], d[k]);
    }
    for (int k = 0; k <= m; k++) {
      f[i][k][0] = max(f[i][k][0], a[k] - sum(i, p[i][k]));
      f[i][k][1] = max(f[i][k][1], d[k] + sum(i - 1, p[i][k]));
      if (i > 1) {
        f[i][k][1] = max(f[i][k][1], b[k] + sum(i - 1, p[i][k]));
        f[i][k][1] = max(f[i][k][1], c[k]);
      }
      f[i][k][0] = max(f[i][k][0], f[i][k][1]);
    }
  }
  ll ans = 0;
  for (auto v : f[n]) {
    ans = max(ans, v[0]);
    ans = max(ans, v[1]);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 112 ms 25660 KB Output is correct
2 Correct 133 ms 29456 KB Output is correct
3 Correct 54 ms 21296 KB Output is correct
4 Correct 73 ms 21304 KB Output is correct
5 Correct 294 ms 48284 KB Output is correct
6 Correct 289 ms 49020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 207 ms 31036 KB Output is correct
3 Correct 234 ms 35564 KB Output is correct
4 Correct 123 ms 25604 KB Output is correct
5 Correct 144 ms 29272 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 55 ms 21368 KB Output is correct
11 Correct 59 ms 21320 KB Output is correct
12 Correct 116 ms 25692 KB Output is correct
13 Correct 155 ms 29296 KB Output is correct
14 Correct 118 ms 25692 KB Output is correct
15 Correct 151 ms 27988 KB Output is correct
16 Correct 116 ms 25736 KB Output is correct
17 Correct 141 ms 28520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 21316 KB Output is correct
2 Correct 54 ms 21388 KB Output is correct
3 Correct 84 ms 24368 KB Output is correct
4 Correct 75 ms 24796 KB Output is correct
5 Correct 109 ms 30516 KB Output is correct
6 Correct 125 ms 30540 KB Output is correct
7 Correct 111 ms 30448 KB Output is correct
8 Correct 109 ms 30536 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 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 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 0 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 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 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 44 ms 3388 KB Output is correct
18 Correct 41 ms 4100 KB Output is correct
19 Correct 32 ms 4044 KB Output is correct
20 Correct 31 ms 3896 KB Output is correct
21 Correct 34 ms 3936 KB Output is correct
22 Correct 79 ms 7500 KB Output is correct
23 Correct 10 ms 1144 KB Output is correct
24 Correct 32 ms 2772 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 9 ms 1108 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 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 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 44 ms 3388 KB Output is correct
18 Correct 41 ms 4100 KB Output is correct
19 Correct 32 ms 4044 KB Output is correct
20 Correct 31 ms 3896 KB Output is correct
21 Correct 34 ms 3936 KB Output is correct
22 Correct 79 ms 7500 KB Output is correct
23 Correct 10 ms 1144 KB Output is correct
24 Correct 32 ms 2772 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 9 ms 1108 KB Output is correct
27 Correct 3 ms 1236 KB Output is correct
28 Correct 204 ms 17592 KB Output is correct
29 Correct 312 ms 24904 KB Output is correct
30 Correct 317 ms 26116 KB Output is correct
31 Correct 357 ms 26088 KB Output is correct
32 Correct 242 ms 24436 KB Output is correct
33 Correct 337 ms 26188 KB Output is correct
34 Correct 388 ms 26212 KB Output is correct
35 Correct 113 ms 10892 KB Output is correct
36 Correct 358 ms 28012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 21316 KB Output is correct
2 Correct 54 ms 21388 KB Output is correct
3 Correct 84 ms 24368 KB Output is correct
4 Correct 75 ms 24796 KB Output is correct
5 Correct 109 ms 30516 KB Output is correct
6 Correct 125 ms 30540 KB Output is correct
7 Correct 111 ms 30448 KB Output is correct
8 Correct 109 ms 30536 KB Output is correct
9 Correct 160 ms 32088 KB Output is correct
10 Correct 76 ms 17340 KB Output is correct
11 Correct 159 ms 34532 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 55 ms 21316 KB Output is correct
19 Correct 54 ms 21380 KB Output is correct
20 Correct 77 ms 21360 KB Output is correct
21 Correct 61 ms 21400 KB Output is correct
22 Correct 150 ms 30540 KB Output is correct
23 Correct 203 ms 36108 KB Output is correct
24 Correct 233 ms 36000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 25660 KB Output is correct
2 Correct 133 ms 29456 KB Output is correct
3 Correct 54 ms 21296 KB Output is correct
4 Correct 73 ms 21304 KB Output is correct
5 Correct 294 ms 48284 KB Output is correct
6 Correct 289 ms 49020 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 207 ms 31036 KB Output is correct
9 Correct 234 ms 35564 KB Output is correct
10 Correct 123 ms 25604 KB Output is correct
11 Correct 144 ms 29272 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 55 ms 21368 KB Output is correct
17 Correct 59 ms 21320 KB Output is correct
18 Correct 116 ms 25692 KB Output is correct
19 Correct 155 ms 29296 KB Output is correct
20 Correct 118 ms 25692 KB Output is correct
21 Correct 151 ms 27988 KB Output is correct
22 Correct 116 ms 25736 KB Output is correct
23 Correct 141 ms 28520 KB Output is correct
24 Correct 71 ms 21316 KB Output is correct
25 Correct 54 ms 21388 KB Output is correct
26 Correct 84 ms 24368 KB Output is correct
27 Correct 75 ms 24796 KB Output is correct
28 Correct 109 ms 30516 KB Output is correct
29 Correct 125 ms 30540 KB Output is correct
30 Correct 111 ms 30448 KB Output is correct
31 Correct 109 ms 30536 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 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 452 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 44 ms 3388 KB Output is correct
49 Correct 41 ms 4100 KB Output is correct
50 Correct 32 ms 4044 KB Output is correct
51 Correct 31 ms 3896 KB Output is correct
52 Correct 34 ms 3936 KB Output is correct
53 Correct 79 ms 7500 KB Output is correct
54 Correct 10 ms 1144 KB Output is correct
55 Correct 32 ms 2772 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 9 ms 1108 KB Output is correct
58 Correct 3 ms 1236 KB Output is correct
59 Correct 204 ms 17592 KB Output is correct
60 Correct 312 ms 24904 KB Output is correct
61 Correct 317 ms 26116 KB Output is correct
62 Correct 357 ms 26088 KB Output is correct
63 Correct 242 ms 24436 KB Output is correct
64 Correct 337 ms 26188 KB Output is correct
65 Correct 388 ms 26212 KB Output is correct
66 Correct 113 ms 10892 KB Output is correct
67 Correct 358 ms 28012 KB Output is correct
68 Correct 160 ms 32088 KB Output is correct
69 Correct 76 ms 17340 KB Output is correct
70 Correct 159 ms 34532 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 55 ms 21316 KB Output is correct
78 Correct 54 ms 21380 KB Output is correct
79 Correct 77 ms 21360 KB Output is correct
80 Correct 61 ms 21400 KB Output is correct
81 Correct 150 ms 30540 KB Output is correct
82 Correct 203 ms 36108 KB Output is correct
83 Correct 233 ms 36000 KB Output is correct
84 Correct 450 ms 42808 KB Output is correct
85 Correct 502 ms 44624 KB Output is correct
86 Correct 350 ms 46324 KB Output is correct
87 Correct 407 ms 48752 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 363 ms 48788 KB Output is correct
90 Correct 347 ms 46832 KB Output is correct
91 Correct 304 ms 44900 KB Output is correct