Submission #641996

# Submission time Handle Problem Language Result Execution time Memory
641996 2022-09-18T08:33:56 Z Vanilla Catfish Farm (IOI22_fish) C++17
100 / 100
564 ms 132596 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
map <int64, int64> dp [maxn][2];
int64 mx [maxn];
vector <pair <int64, int64> > p[maxn];
vector <pair <int64, int64> > pref [maxn], suff[maxn];
vector <int64> pos [maxn];

int64 psum (int64 i, int64 j) {
  auto it = lower_bound(p[i].begin(), p[i].end(), make_pair(j, (int64) 1e18));
  if (it == p[i].begin()) return 0;
  return (--it)->second;
}

int64 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]].push_back(++y[i]);
    p[x[i]].push_back({y[i], w[i]});
  }
  for (int i = 1; i <= n; i++){
    sort(p[i].begin(), p[i].end());
    sort(pos[i].begin(), pos[i].end());
    int64 sum = 0;
    for (auto& [j, c]: p[i]) {
      int64 t = sum;
      sum+=c;
      c+=t;
      // cout << i << " " << j << " " << c << "\n";
    }
  }
  // cout << "> " << psum(1, 3) << " " << psum(1, 5) << " " << psum(1, 2) << "\n";
  for (int i = 1; i <= n; i++){
    vector <int64> ps = {0, n};
    for (auto j: pos[i-1]) ps.push_back(j);
    for (auto j: pos[i+1]) ps.push_back(j);
    sort(ps.begin(), ps.end());
    for (auto j: ps){
      auto it = lower_bound(suff[i-1].begin(), suff[i-1].end(), make_pair(j, -1ll));
      dp[i][j][0] = -psum(i, j);
      if (it != suff[i-1].end()) dp[i][j][0] += it->second;

      // dp[i][j][0] = suff[i-1][j] - p[i][j];

      it = lower_bound(pref[i - 1].begin(), pref[i - 1].end(), make_pair(j, (int64) 1e18));
      dp[i][j][1] = ((i - 2 >= 0) ? mx[i-2]: 0) + psum(i-1, j);
      if (it != pref[i-1].begin()) dp[i][j][1] = max(dp[i][j][1], (--it)->second + psum(i-1, j));
      // dp[i][j][1] = max(mx[i-2] + p[i-1][j], pref[i-1][j] + p[i-1][j]);


      mx[i] = max({mx[i], dp[i][j][0], dp[i][j][1]});
    }
    for (auto j: ps) {
      pref[i].push_back(make_pair(j, max((pref[i].empty() ? 0ll: pref[i].back().second), dp[i][j][1] - psum(i, j))));
    }
    reverse(ps.begin(), ps.end());
    for (auto j: ps) {
      suff[i].push_back(make_pair(j, max((suff[i].empty() ? 0ll: suff[i].back().second), max(dp[i][j][0], dp[i][j][1]) + psum(i + 1, j))));
    }
    reverse(suff[i].begin(), suff[i].end());
    // for (auto [j, c]: suff[i]) {
    //   cout << i << " " << j << " " << c << "\n";
    // }
    // for (int j = 0; j <= n; j++){
    //   pref[i][j] = max((j != 0 ? pref[i][j - 1]: 0ll), dp[i][j][1] - p[i][j]);
    // }
    // for (int j = n; j >= 0; j--){
    //   suff[i][j] = max((j != n ? suff[i][j + 1] : 0ll), max(dp[i][j][0], dp[i][j][1]) + p[i + 1][j]);
    // }
  }
  return mx[n];
}
# Verdict Execution time Memory Grader output
1 Correct 123 ms 75308 KB Output is correct
2 Correct 144 ms 80936 KB Output is correct
3 Correct 83 ms 66740 KB Output is correct
4 Correct 79 ms 66740 KB Output is correct
5 Correct 337 ms 115320 KB Output is correct
6 Correct 501 ms 126448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37784 KB Output is correct
2 Correct 215 ms 84760 KB Output is correct
3 Correct 248 ms 91864 KB Output is correct
4 Correct 125 ms 75208 KB Output is correct
5 Correct 141 ms 80900 KB Output is correct
6 Correct 19 ms 37788 KB Output is correct
7 Correct 18 ms 37884 KB Output is correct
8 Correct 20 ms 37808 KB Output is correct
9 Correct 17 ms 37844 KB Output is correct
10 Correct 78 ms 66828 KB Output is correct
11 Correct 78 ms 66764 KB Output is correct
12 Correct 135 ms 78420 KB Output is correct
13 Correct 153 ms 84244 KB Output is correct
14 Correct 136 ms 76908 KB Output is correct
15 Correct 158 ms 78464 KB Output is correct
16 Correct 132 ms 76852 KB Output is correct
17 Correct 153 ms 81264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 66824 KB Output is correct
2 Correct 79 ms 66708 KB Output is correct
3 Correct 146 ms 79484 KB Output is correct
4 Correct 125 ms 77472 KB Output is correct
5 Correct 195 ms 94236 KB Output is correct
6 Correct 191 ms 94284 KB Output is correct
7 Correct 197 ms 94108 KB Output is correct
8 Correct 198 ms 94180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 17 ms 37776 KB Output is correct
4 Correct 18 ms 37764 KB Output is correct
5 Correct 17 ms 37792 KB Output is correct
6 Correct 18 ms 37844 KB Output is correct
7 Correct 18 ms 37764 KB Output is correct
8 Correct 18 ms 37892 KB Output is correct
9 Correct 18 ms 37972 KB Output is correct
10 Correct 20 ms 38356 KB Output is correct
11 Correct 18 ms 37972 KB Output is correct
12 Correct 20 ms 38140 KB Output is correct
13 Correct 18 ms 37944 KB Output is correct
14 Correct 19 ms 38068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 17 ms 37776 KB Output is correct
4 Correct 18 ms 37764 KB Output is correct
5 Correct 17 ms 37792 KB Output is correct
6 Correct 18 ms 37844 KB Output is correct
7 Correct 18 ms 37764 KB Output is correct
8 Correct 18 ms 37892 KB Output is correct
9 Correct 18 ms 37972 KB Output is correct
10 Correct 20 ms 38356 KB Output is correct
11 Correct 18 ms 37972 KB Output is correct
12 Correct 20 ms 38140 KB Output is correct
13 Correct 18 ms 37944 KB Output is correct
14 Correct 19 ms 38068 KB Output is correct
15 Correct 19 ms 38032 KB Output is correct
16 Correct 20 ms 38160 KB Output is correct
17 Correct 64 ms 43860 KB Output is correct
18 Correct 69 ms 45808 KB Output is correct
19 Correct 61 ms 46240 KB Output is correct
20 Correct 61 ms 46468 KB Output is correct
21 Correct 60 ms 46300 KB Output is correct
22 Correct 115 ms 52812 KB Output is correct
23 Correct 31 ms 39248 KB Output is correct
24 Correct 50 ms 42336 KB Output is correct
25 Correct 20 ms 38100 KB Output is correct
26 Correct 25 ms 39124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 18 ms 37844 KB Output is correct
3 Correct 17 ms 37776 KB Output is correct
4 Correct 18 ms 37764 KB Output is correct
5 Correct 17 ms 37792 KB Output is correct
6 Correct 18 ms 37844 KB Output is correct
7 Correct 18 ms 37764 KB Output is correct
8 Correct 18 ms 37892 KB Output is correct
9 Correct 18 ms 37972 KB Output is correct
10 Correct 20 ms 38356 KB Output is correct
11 Correct 18 ms 37972 KB Output is correct
12 Correct 20 ms 38140 KB Output is correct
13 Correct 18 ms 37944 KB Output is correct
14 Correct 19 ms 38068 KB Output is correct
15 Correct 19 ms 38032 KB Output is correct
16 Correct 20 ms 38160 KB Output is correct
17 Correct 64 ms 43860 KB Output is correct
18 Correct 69 ms 45808 KB Output is correct
19 Correct 61 ms 46240 KB Output is correct
20 Correct 61 ms 46468 KB Output is correct
21 Correct 60 ms 46300 KB Output is correct
22 Correct 115 ms 52812 KB Output is correct
23 Correct 31 ms 39248 KB Output is correct
24 Correct 50 ms 42336 KB Output is correct
25 Correct 20 ms 38100 KB Output is correct
26 Correct 25 ms 39124 KB Output is correct
27 Correct 22 ms 39508 KB Output is correct
28 Correct 251 ms 71436 KB Output is correct
29 Correct 340 ms 81388 KB Output is correct
30 Correct 321 ms 84380 KB Output is correct
31 Correct 328 ms 84464 KB Output is correct
32 Correct 345 ms 85452 KB Output is correct
33 Correct 320 ms 84500 KB Output is correct
34 Correct 325 ms 84264 KB Output is correct
35 Correct 136 ms 58448 KB Output is correct
36 Correct 353 ms 85712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 66824 KB Output is correct
2 Correct 79 ms 66708 KB Output is correct
3 Correct 146 ms 79484 KB Output is correct
4 Correct 125 ms 77472 KB Output is correct
5 Correct 195 ms 94236 KB Output is correct
6 Correct 191 ms 94284 KB Output is correct
7 Correct 197 ms 94108 KB Output is correct
8 Correct 198 ms 94180 KB Output is correct
9 Correct 220 ms 94240 KB Output is correct
10 Correct 149 ms 74620 KB Output is correct
11 Correct 294 ms 111716 KB Output is correct
12 Correct 18 ms 37844 KB Output is correct
13 Correct 18 ms 37816 KB Output is correct
14 Correct 18 ms 37820 KB Output is correct
15 Correct 19 ms 37824 KB Output is correct
16 Correct 18 ms 37844 KB Output is correct
17 Correct 18 ms 37852 KB Output is correct
18 Correct 80 ms 66728 KB Output is correct
19 Correct 86 ms 66840 KB Output is correct
20 Correct 81 ms 66752 KB Output is correct
21 Correct 79 ms 66744 KB Output is correct
22 Correct 245 ms 92112 KB Output is correct
23 Correct 320 ms 111744 KB Output is correct
24 Correct 313 ms 113516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 75308 KB Output is correct
2 Correct 144 ms 80936 KB Output is correct
3 Correct 83 ms 66740 KB Output is correct
4 Correct 79 ms 66740 KB Output is correct
5 Correct 337 ms 115320 KB Output is correct
6 Correct 501 ms 126448 KB Output is correct
7 Correct 18 ms 37784 KB Output is correct
8 Correct 215 ms 84760 KB Output is correct
9 Correct 248 ms 91864 KB Output is correct
10 Correct 125 ms 75208 KB Output is correct
11 Correct 141 ms 80900 KB Output is correct
12 Correct 19 ms 37788 KB Output is correct
13 Correct 18 ms 37884 KB Output is correct
14 Correct 20 ms 37808 KB Output is correct
15 Correct 17 ms 37844 KB Output is correct
16 Correct 78 ms 66828 KB Output is correct
17 Correct 78 ms 66764 KB Output is correct
18 Correct 135 ms 78420 KB Output is correct
19 Correct 153 ms 84244 KB Output is correct
20 Correct 136 ms 76908 KB Output is correct
21 Correct 158 ms 78464 KB Output is correct
22 Correct 132 ms 76852 KB Output is correct
23 Correct 153 ms 81264 KB Output is correct
24 Correct 83 ms 66824 KB Output is correct
25 Correct 79 ms 66708 KB Output is correct
26 Correct 146 ms 79484 KB Output is correct
27 Correct 125 ms 77472 KB Output is correct
28 Correct 195 ms 94236 KB Output is correct
29 Correct 191 ms 94284 KB Output is correct
30 Correct 197 ms 94108 KB Output is correct
31 Correct 198 ms 94180 KB Output is correct
32 Correct 18 ms 37844 KB Output is correct
33 Correct 18 ms 37844 KB Output is correct
34 Correct 17 ms 37776 KB Output is correct
35 Correct 18 ms 37764 KB Output is correct
36 Correct 17 ms 37792 KB Output is correct
37 Correct 18 ms 37844 KB Output is correct
38 Correct 18 ms 37764 KB Output is correct
39 Correct 18 ms 37892 KB Output is correct
40 Correct 18 ms 37972 KB Output is correct
41 Correct 20 ms 38356 KB Output is correct
42 Correct 18 ms 37972 KB Output is correct
43 Correct 20 ms 38140 KB Output is correct
44 Correct 18 ms 37944 KB Output is correct
45 Correct 19 ms 38068 KB Output is correct
46 Correct 19 ms 38032 KB Output is correct
47 Correct 20 ms 38160 KB Output is correct
48 Correct 64 ms 43860 KB Output is correct
49 Correct 69 ms 45808 KB Output is correct
50 Correct 61 ms 46240 KB Output is correct
51 Correct 61 ms 46468 KB Output is correct
52 Correct 60 ms 46300 KB Output is correct
53 Correct 115 ms 52812 KB Output is correct
54 Correct 31 ms 39248 KB Output is correct
55 Correct 50 ms 42336 KB Output is correct
56 Correct 20 ms 38100 KB Output is correct
57 Correct 25 ms 39124 KB Output is correct
58 Correct 22 ms 39508 KB Output is correct
59 Correct 251 ms 71436 KB Output is correct
60 Correct 340 ms 81388 KB Output is correct
61 Correct 321 ms 84380 KB Output is correct
62 Correct 328 ms 84464 KB Output is correct
63 Correct 345 ms 85452 KB Output is correct
64 Correct 320 ms 84500 KB Output is correct
65 Correct 325 ms 84264 KB Output is correct
66 Correct 136 ms 58448 KB Output is correct
67 Correct 353 ms 85712 KB Output is correct
68 Correct 220 ms 94240 KB Output is correct
69 Correct 149 ms 74620 KB Output is correct
70 Correct 294 ms 111716 KB Output is correct
71 Correct 18 ms 37844 KB Output is correct
72 Correct 18 ms 37816 KB Output is correct
73 Correct 18 ms 37820 KB Output is correct
74 Correct 19 ms 37824 KB Output is correct
75 Correct 18 ms 37844 KB Output is correct
76 Correct 18 ms 37852 KB Output is correct
77 Correct 80 ms 66728 KB Output is correct
78 Correct 86 ms 66840 KB Output is correct
79 Correct 81 ms 66752 KB Output is correct
80 Correct 79 ms 66744 KB Output is correct
81 Correct 245 ms 92112 KB Output is correct
82 Correct 320 ms 111744 KB Output is correct
83 Correct 313 ms 113516 KB Output is correct
84 Correct 503 ms 109300 KB Output is correct
85 Correct 500 ms 109980 KB Output is correct
86 Correct 532 ms 128236 KB Output is correct
87 Correct 530 ms 132192 KB Output is correct
88 Correct 20 ms 37860 KB Output is correct
89 Correct 564 ms 132596 KB Output is correct
90 Correct 431 ms 119232 KB Output is correct
91 Correct 387 ms 115612 KB Output is correct