Submission #824809

# Submission time Handle Problem Language Result Execution time Memory
824809 2023-08-14T10:40:26 Z LittleCube Catfish Farm (IOI22_fish) C++17
100 / 100
149 ms 36924 KB
#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

// every conponent can only be decreasing and increasing (except for the first and last, they can only be inc/decreasing).
vector<pll> pos[100005];
vector<ll> up[100005], down[100005];
ll non[100005], sz[100005];

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W)
{
  for (int i = 0; i < M; i++)
    pos[X[i] + 1].emplace_back(pll(Y[i], W[i]));
  pos[0] = {pll(-1, 0)};
  for (int i = 1; i <= N; i++)
  {
    sz[0] = 1;
    sort(pos[i].begin(), pos[i].end());
    sz[i] = pos[i].size();
  }
  up[0] = {0};
  down[0] = {(ll)-1e18};
  non[0] = -1e18;
  for (int i = 1; i <= N; i++)
  {
    up[i].resize(sz[i]);
    down[i].resize(sz[i]);

    non[i] = max(0LL, non[i - 1]);
    if (!down[i - 1].empty())
      non[i] = max(non[i], down[i - 1].front());
    if (!up[i - 1].empty())
      non[i] = max(non[i], up[i - 1].back());

    {
      ll acc = non[i - 1];
      for (int j = sz[i] - 1, k = sz[i - 1] - 1; j >= 0; j--)
      {
        while (k >= 0 && pos[i - 1][k].F > pos[i][j].F)
          acc = max(acc, down[i - 1][k]), k--;
        down[i][j] = acc + pos[i][j].S;
        acc = max(acc, down[i][j]);
      }
    }
    {
      ll acc = non[i - 1];
      if (!down[i - 1].empty())
        acc = max(acc, down[i - 1].front());
      for (int j = 0, k = 0; j < sz[i]; j++)
      {
        while (k < sz[i - 1] && pos[i - 1][k].F < pos[i][j].F)
          acc = max(acc, up[i - 1][k]), k++;
        up[i][j] = acc + pos[i][j].S;
        acc = max(acc, up[i][j]);
      }
    }
  }
  ll ans = non[N];
  if (!down[N].empty())
    ans = max(ans, down[N].front());
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 14544 KB Output is correct
2 Correct 36 ms 16040 KB Output is correct
3 Correct 4 ms 8888 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 102 ms 31672 KB Output is correct
6 Correct 120 ms 35564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7356 KB Output is correct
2 Correct 57 ms 20408 KB Output is correct
3 Correct 69 ms 23280 KB Output is correct
4 Correct 35 ms 14544 KB Output is correct
5 Correct 42 ms 16096 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7352 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 5 ms 8916 KB Output is correct
11 Correct 6 ms 8916 KB Output is correct
12 Correct 30 ms 14524 KB Output is correct
13 Correct 35 ms 16048 KB Output is correct
14 Correct 30 ms 14592 KB Output is correct
15 Correct 33 ms 15432 KB Output is correct
16 Correct 30 ms 14556 KB Output is correct
17 Correct 33 ms 15300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8820 KB Output is correct
3 Correct 26 ms 15912 KB Output is correct
4 Correct 25 ms 13656 KB Output is correct
5 Correct 48 ms 22160 KB Output is correct
6 Correct 43 ms 21552 KB Output is correct
7 Correct 43 ms 22084 KB Output is correct
8 Correct 45 ms 22208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7360 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7360 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7352 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7388 KB Output is correct
12 Correct 4 ms 7364 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 4 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7360 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7360 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7352 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7388 KB Output is correct
12 Correct 4 ms 7364 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 4 ms 7368 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 17 ms 10720 KB Output is correct
18 Correct 17 ms 11224 KB Output is correct
19 Correct 16 ms 11076 KB Output is correct
20 Correct 17 ms 11072 KB Output is correct
21 Correct 20 ms 11064 KB Output is correct
22 Correct 35 ms 14924 KB Output is correct
23 Correct 6 ms 8076 KB Output is correct
24 Correct 13 ms 9704 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 7 ms 8008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7360 KB Output is correct
3 Correct 3 ms 7252 KB Output is correct
4 Correct 3 ms 7360 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7352 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7388 KB Output is correct
12 Correct 4 ms 7364 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 4 ms 7368 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 17 ms 10720 KB Output is correct
18 Correct 17 ms 11224 KB Output is correct
19 Correct 16 ms 11076 KB Output is correct
20 Correct 17 ms 11072 KB Output is correct
21 Correct 20 ms 11064 KB Output is correct
22 Correct 35 ms 14924 KB Output is correct
23 Correct 6 ms 8076 KB Output is correct
24 Correct 13 ms 9704 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 7 ms 8008 KB Output is correct
27 Correct 4 ms 7764 KB Output is correct
28 Correct 67 ms 24972 KB Output is correct
29 Correct 122 ms 31588 KB Output is correct
30 Correct 98 ms 30940 KB Output is correct
31 Correct 115 ms 30956 KB Output is correct
32 Correct 90 ms 32256 KB Output is correct
33 Correct 112 ms 30932 KB Output is correct
34 Correct 96 ms 30948 KB Output is correct
35 Correct 38 ms 16716 KB Output is correct
36 Correct 106 ms 32212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8820 KB Output is correct
3 Correct 26 ms 15912 KB Output is correct
4 Correct 25 ms 13656 KB Output is correct
5 Correct 48 ms 22160 KB Output is correct
6 Correct 43 ms 21552 KB Output is correct
7 Correct 43 ms 22084 KB Output is correct
8 Correct 45 ms 22208 KB Output is correct
9 Correct 44 ms 21960 KB Output is correct
10 Correct 42 ms 17736 KB Output is correct
11 Correct 88 ms 28212 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 3 ms 7348 KB Output is correct
14 Correct 3 ms 7352 KB Output is correct
15 Correct 5 ms 7252 KB Output is correct
16 Correct 3 ms 7252 KB Output is correct
17 Correct 3 ms 7252 KB Output is correct
18 Correct 4 ms 8916 KB Output is correct
19 Correct 4 ms 8916 KB Output is correct
20 Correct 5 ms 8916 KB Output is correct
21 Correct 5 ms 8916 KB Output is correct
22 Correct 67 ms 20036 KB Output is correct
23 Correct 95 ms 28256 KB Output is correct
24 Correct 100 ms 28716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 14544 KB Output is correct
2 Correct 36 ms 16040 KB Output is correct
3 Correct 4 ms 8888 KB Output is correct
4 Correct 4 ms 8916 KB Output is correct
5 Correct 102 ms 31672 KB Output is correct
6 Correct 120 ms 35564 KB Output is correct
7 Correct 3 ms 7356 KB Output is correct
8 Correct 57 ms 20408 KB Output is correct
9 Correct 69 ms 23280 KB Output is correct
10 Correct 35 ms 14544 KB Output is correct
11 Correct 42 ms 16096 KB Output is correct
12 Correct 3 ms 7252 KB Output is correct
13 Correct 3 ms 7352 KB Output is correct
14 Correct 3 ms 7252 KB Output is correct
15 Correct 3 ms 7252 KB Output is correct
16 Correct 5 ms 8916 KB Output is correct
17 Correct 6 ms 8916 KB Output is correct
18 Correct 30 ms 14524 KB Output is correct
19 Correct 35 ms 16048 KB Output is correct
20 Correct 30 ms 14592 KB Output is correct
21 Correct 33 ms 15432 KB Output is correct
22 Correct 30 ms 14556 KB Output is correct
23 Correct 33 ms 15300 KB Output is correct
24 Correct 4 ms 8916 KB Output is correct
25 Correct 4 ms 8820 KB Output is correct
26 Correct 26 ms 15912 KB Output is correct
27 Correct 25 ms 13656 KB Output is correct
28 Correct 48 ms 22160 KB Output is correct
29 Correct 43 ms 21552 KB Output is correct
30 Correct 43 ms 22084 KB Output is correct
31 Correct 45 ms 22208 KB Output is correct
32 Correct 3 ms 7252 KB Output is correct
33 Correct 3 ms 7360 KB Output is correct
34 Correct 3 ms 7252 KB Output is correct
35 Correct 3 ms 7360 KB Output is correct
36 Correct 4 ms 7356 KB Output is correct
37 Correct 4 ms 7252 KB Output is correct
38 Correct 4 ms 7356 KB Output is correct
39 Correct 4 ms 7352 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 4 ms 7508 KB Output is correct
42 Correct 4 ms 7388 KB Output is correct
43 Correct 4 ms 7364 KB Output is correct
44 Correct 4 ms 7360 KB Output is correct
45 Correct 4 ms 7368 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 5 ms 7404 KB Output is correct
48 Correct 17 ms 10720 KB Output is correct
49 Correct 17 ms 11224 KB Output is correct
50 Correct 16 ms 11076 KB Output is correct
51 Correct 17 ms 11072 KB Output is correct
52 Correct 20 ms 11064 KB Output is correct
53 Correct 35 ms 14924 KB Output is correct
54 Correct 6 ms 8076 KB Output is correct
55 Correct 13 ms 9704 KB Output is correct
56 Correct 4 ms 7380 KB Output is correct
57 Correct 7 ms 8008 KB Output is correct
58 Correct 4 ms 7764 KB Output is correct
59 Correct 67 ms 24972 KB Output is correct
60 Correct 122 ms 31588 KB Output is correct
61 Correct 98 ms 30940 KB Output is correct
62 Correct 115 ms 30956 KB Output is correct
63 Correct 90 ms 32256 KB Output is correct
64 Correct 112 ms 30932 KB Output is correct
65 Correct 96 ms 30948 KB Output is correct
66 Correct 38 ms 16716 KB Output is correct
67 Correct 106 ms 32212 KB Output is correct
68 Correct 44 ms 21960 KB Output is correct
69 Correct 42 ms 17736 KB Output is correct
70 Correct 88 ms 28212 KB Output is correct
71 Correct 4 ms 7352 KB Output is correct
72 Correct 3 ms 7348 KB Output is correct
73 Correct 3 ms 7352 KB Output is correct
74 Correct 5 ms 7252 KB Output is correct
75 Correct 3 ms 7252 KB Output is correct
76 Correct 3 ms 7252 KB Output is correct
77 Correct 4 ms 8916 KB Output is correct
78 Correct 4 ms 8916 KB Output is correct
79 Correct 5 ms 8916 KB Output is correct
80 Correct 5 ms 8916 KB Output is correct
81 Correct 67 ms 20036 KB Output is correct
82 Correct 95 ms 28256 KB Output is correct
83 Correct 100 ms 28716 KB Output is correct
84 Correct 109 ms 31316 KB Output is correct
85 Correct 105 ms 31128 KB Output is correct
86 Correct 149 ms 36176 KB Output is correct
87 Correct 144 ms 36900 KB Output is correct
88 Correct 4 ms 7356 KB Output is correct
89 Correct 140 ms 36924 KB Output is correct
90 Correct 131 ms 34140 KB Output is correct
91 Correct 108 ms 33316 KB Output is correct