Submission #839078

# Submission time Handle Problem Language Result Execution time Memory
839078 2023-08-28T15:12:29 Z abczz Catfish Farm (IOI22_fish) C++17
100 / 100
227 ms 42444 KB
#include "fish.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <map>
#include <queue>
#define ll long long
using namespace std;

vector <array<ll, 2>> V[100000];
vector <ll> pre;
vector <array<ll, 3>> dp[100000];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  ll f = -1e18, j, k, l, s = 0, t = 0, v, x, u, p = -1e18, mx, mx2, cur;
  map <ll, ll> mp;
  for (int i=0; i<M; ++i) {
    V[X[i]].push_back({Y[i], W[i]});
  }
  for (int i=0; i<N; ++i) {
    sort(V[i].begin(), V[i].end());
  }
  j = 0;
  s = 0;
  for (auto [y, w] : V[1]) {
    s += w;
    dp[0].push_back({y, 0, (ll)-1e18});
    f = max(f, s);
  }
  for (int i=1; i<N; ++i) {
    if (i >= 3) {
      j = 0;
      s = 0;
      for (auto [y, w, a] : dp[i-3]) {
        w = max(w, a);
        while (j < V[i-2].size() && V[i-2][j][0] <= y) {
          s += V[i-2][j][1];
          ++j;
        }
        p = max(p, s+w);
      }
    }
    mp.clear();
    mx = mx2 = -1e18, s = 0;
    if (i >= 2) {
      j = 0;
      for (auto [y, w, a] : dp[i-2]) {
        w = max(w, a);
        while (j < V[i-1].size() && V[i-1][j][0] <= y) {
          s += V[i-1][j][1];
          ++j;
        }
        mx = max(mx, w);
        mx2 = max(mx2, w+s);
      }
    }
    for (auto [y, w] : V[i-1]) {
      ++mp[y];
    }
    if (i != N-1) {
      for (auto [y, w] : V[i+1]) {
        ++mp[y];
      }
    }
    s = j = k = t = 0;
    v = x = -1e18;
    pre.clear();
    for (auto [y, w, a] : dp[i-1]) {
      while (j < V[i].size() && V[i][j][0] <= y) {
        s += V[i][j][1];
        ++j;
      }
      while (k < V[i-1].size() && V[i-1][k][0] <= y) {
        t += V[i-1][k][1];
        ++k;
      }
      v = max(v, max(w, a)+s);
      x = max(x, w-t);
    }
    s = j = k = t = l = u = 0;
    for (auto [y, z] : mp) {
      while (j < V[i].size() && V[i][j][0] <= y) {
        s += V[i][j][1];
        ++j;
      }
      while (k < V[i-1].size() && V[i-1][k][0] <= y) {
        t += V[i-1][k][1];
        ++k;
      }
      while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
        u += V[i+1][l][1];
        ++l;
      }
      cur = max(max(t, p+t), max(mx2, mx+t));
      //cout << v << " " << x << " " << s << " " << t << endl;
      //cout << cur << endl;
      cur = max(cur, x+t);
      //cout << cur << endl;
      dp[i].push_back({y, cur, v-s});
      //cout << i << " " << y << " " << cur << "/" << v-s << endl;
      cur = max(cur, v-s);
      f = max(f, cur + u);
    }
  }
  return f;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while (j < V[i-2].size() && V[i-2][j][0] <= y) {
      |                ~~^~~~~~~~~~~~~~~
fish.cpp:50:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while (j < V[i-1].size() && V[i-1][j][0] <= y) {
      |                ~~^~~~~~~~~~~~~~~
fish.cpp:70:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |       while (j < V[i].size() && V[i][j][0] <= y) {
      |              ~~^~~~~~~~~~~~~
fish.cpp:74:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |       while (k < V[i-1].size() && V[i-1][k][0] <= y) {
      |              ~~^~~~~~~~~~~~~~~
fish.cpp:83:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |       while (j < V[i].size() && V[i][j][0] <= y) {
      |              ~~^~~~~~~~~~~~~
fish.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |       while (k < V[i-1].size() && V[i-1][k][0] <= y) {
      |              ~~^~~~~~~~~~~~~~~
fish.cpp:91:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |       while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
      |                          ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 17724 KB Output is correct
2 Correct 60 ms 19812 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 192 ms 39048 KB Output is correct
6 Correct 174 ms 39612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 100 ms 24856 KB Output is correct
3 Correct 110 ms 28332 KB Output is correct
4 Correct 46 ms 17708 KB Output is correct
5 Correct 55 ms 19736 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5004 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 46 ms 19772 KB Output is correct
13 Correct 60 ms 22096 KB Output is correct
14 Correct 42 ms 14944 KB Output is correct
15 Correct 46 ms 15812 KB Output is correct
16 Correct 41 ms 14896 KB Output is correct
17 Correct 46 ms 15764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4996 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 24 ms 9748 KB Output is correct
4 Correct 17 ms 8256 KB Output is correct
5 Correct 42 ms 13588 KB Output is correct
6 Correct 36 ms 13572 KB Output is correct
7 Correct 45 ms 13520 KB Output is correct
8 Correct 44 ms 13520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 3 ms 5012 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 3 ms 5012 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 5204 KB Output is correct
17 Correct 22 ms 9784 KB Output is correct
18 Correct 21 ms 10120 KB Output is correct
19 Correct 19 ms 10340 KB Output is correct
20 Correct 19 ms 9992 KB Output is correct
21 Correct 19 ms 9892 KB Output is correct
22 Correct 35 ms 14236 KB Output is correct
23 Correct 7 ms 6100 KB Output is correct
24 Correct 18 ms 8636 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 6 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 3 ms 5012 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 5204 KB Output is correct
17 Correct 22 ms 9784 KB Output is correct
18 Correct 21 ms 10120 KB Output is correct
19 Correct 19 ms 10340 KB Output is correct
20 Correct 19 ms 9992 KB Output is correct
21 Correct 19 ms 9892 KB Output is correct
22 Correct 35 ms 14236 KB Output is correct
23 Correct 7 ms 6100 KB Output is correct
24 Correct 18 ms 8636 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 6 ms 5972 KB Output is correct
27 Correct 4 ms 5336 KB Output is correct
28 Correct 99 ms 27300 KB Output is correct
29 Correct 144 ms 34660 KB Output is correct
30 Correct 167 ms 40760 KB Output is correct
31 Correct 159 ms 40780 KB Output is correct
32 Correct 112 ms 33852 KB Output is correct
33 Correct 164 ms 40824 KB Output is correct
34 Correct 163 ms 40864 KB Output is correct
35 Correct 68 ms 19752 KB Output is correct
36 Correct 191 ms 38708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4996 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 24 ms 9748 KB Output is correct
4 Correct 17 ms 8256 KB Output is correct
5 Correct 42 ms 13588 KB Output is correct
6 Correct 36 ms 13572 KB Output is correct
7 Correct 45 ms 13520 KB Output is correct
8 Correct 44 ms 13520 KB Output is correct
9 Correct 46 ms 16712 KB Output is correct
10 Correct 41 ms 12964 KB Output is correct
11 Correct 82 ms 21120 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 60 ms 17440 KB Output is correct
23 Correct 104 ms 26256 KB Output is correct
24 Correct 102 ms 26936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 17724 KB Output is correct
2 Correct 60 ms 19812 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 192 ms 39048 KB Output is correct
6 Correct 174 ms 39612 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 100 ms 24856 KB Output is correct
9 Correct 110 ms 28332 KB Output is correct
10 Correct 46 ms 17708 KB Output is correct
11 Correct 55 ms 19736 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 46 ms 19772 KB Output is correct
19 Correct 60 ms 22096 KB Output is correct
20 Correct 42 ms 14944 KB Output is correct
21 Correct 46 ms 15812 KB Output is correct
22 Correct 41 ms 14896 KB Output is correct
23 Correct 46 ms 15764 KB Output is correct
24 Correct 4 ms 4996 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 24 ms 9748 KB Output is correct
27 Correct 17 ms 8256 KB Output is correct
28 Correct 42 ms 13588 KB Output is correct
29 Correct 36 ms 13572 KB Output is correct
30 Correct 45 ms 13520 KB Output is correct
31 Correct 44 ms 13520 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 4948 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 3 ms 5012 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 2 ms 4948 KB Output is correct
47 Correct 3 ms 5204 KB Output is correct
48 Correct 22 ms 9784 KB Output is correct
49 Correct 21 ms 10120 KB Output is correct
50 Correct 19 ms 10340 KB Output is correct
51 Correct 19 ms 9992 KB Output is correct
52 Correct 19 ms 9892 KB Output is correct
53 Correct 35 ms 14236 KB Output is correct
54 Correct 7 ms 6100 KB Output is correct
55 Correct 18 ms 8636 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 6 ms 5972 KB Output is correct
58 Correct 4 ms 5336 KB Output is correct
59 Correct 99 ms 27300 KB Output is correct
60 Correct 144 ms 34660 KB Output is correct
61 Correct 167 ms 40760 KB Output is correct
62 Correct 159 ms 40780 KB Output is correct
63 Correct 112 ms 33852 KB Output is correct
64 Correct 164 ms 40824 KB Output is correct
65 Correct 163 ms 40864 KB Output is correct
66 Correct 68 ms 19752 KB Output is correct
67 Correct 191 ms 38708 KB Output is correct
68 Correct 46 ms 16712 KB Output is correct
69 Correct 41 ms 12964 KB Output is correct
70 Correct 82 ms 21120 KB Output is correct
71 Correct 2 ms 4948 KB Output is correct
72 Correct 2 ms 4948 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 2 ms 4948 KB Output is correct
75 Correct 2 ms 4948 KB Output is correct
76 Correct 2 ms 4948 KB Output is correct
77 Correct 4 ms 5076 KB Output is correct
78 Correct 3 ms 5004 KB Output is correct
79 Correct 3 ms 4948 KB Output is correct
80 Correct 3 ms 4948 KB Output is correct
81 Correct 60 ms 17440 KB Output is correct
82 Correct 104 ms 26256 KB Output is correct
83 Correct 102 ms 26936 KB Output is correct
84 Correct 173 ms 34056 KB Output is correct
85 Correct 175 ms 36608 KB Output is correct
86 Correct 208 ms 42056 KB Output is correct
87 Correct 227 ms 42384 KB Output is correct
88 Correct 2 ms 4948 KB Output is correct
89 Correct 198 ms 42444 KB Output is correct
90 Correct 172 ms 39516 KB Output is correct
91 Correct 138 ms 35148 KB Output is correct