Submission #659596

# Submission time Handle Problem Language Result Execution time Memory
659596 2022-11-18T17:40:58 Z peijar Catfish Farm (IOI22_fish) C++17
37 / 100
1000 ms 60724 KB
#include "fish.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e18;

const int MAXN = 1e5;
vector<pair<int, int>> dp[MAXN][2];

int eval(int i, int side, int h) {
  auto it = upper_bound(dp[i][side].begin(), dp[i][side].end(), pair(h, INF));
  assert(it != dp[i][side].begin());
  --it;
  return it->second;
}

int max_weights(signed N, signed M, vector<signed> X, vector<signed> Y,
                vector<signed> W) {
  vector<vector<pair<int, int>>> onCol(N);
  vector<vector<int>> prefSum(N);
  for (int i = 0; i < M; ++i)
    onCol[X[i]].emplace_back(Y[i] + 1, W[i]);
  for (int i = 0; i < N; ++i) {
    sort(onCol[i].begin(), onCol[i].end());
    prefSum[i].resize(onCol[i].size() + 1);
    for (int j = 0; j < (int)onCol[i].size(); ++j)
      prefSum[i][j + 1] = prefSum[i][j] + onCol[i][j].second;
  }

  vector<vector<int>> interesting(N);
  for (int i = 0; i < N; ++i) {
    interesting[i].push_back(0);
    for (auto [y, w] : onCol[i])
      interesting[i].push_back(y);
    if (i)
      for (auto [y, w] : onCol[i - 1])
        interesting[i].push_back(y);
    if (i + 1 < N)
      for (auto [y, w] : onCol[i + 1])
        interesting[i].push_back(y);
    interesting[i].push_back(N);
    sort(interesting[i].begin(), interesting[i].end());
    interesting[i].resize(unique(interesting[i].begin(), interesting[i].end()) -
                          interesting[i].begin());
  }
  dp[0][0].emplace_back(0, 0);
  dp[0][1].emplace_back(0, 0);

  auto getSum = [&](int i, int h1, int h2) -> int {
    int lo = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h1, INF)) -
             onCol[i].begin();
    int up = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h2, INF)) -
             onCol[i].begin();
    return prefSum[i][up] - prefSum[i][lo];
  };

  int sol = 0;
  for (int i = 1; i < N; ++i) {
    int nbInteressants = interesting[i].size();
    for (int iHauteur = 0; iHauteur < nbInteressants; ++iHauteur) {
      int h = interesting[i][iHauteur];
      // 1
      int v1 = 0;
      int v0 = 0;
      for (int jHauteur = 0; jHauteur < (int)interesting[i - 1].size();
           ++jHauteur) {
        int oldH = interesting[i - 1][jHauteur];
        if (oldH > h)
          v1 = max(v1, getSum(i, h, oldH) + eval(i - 1, 1, oldH));
        if (oldH >= h)
          v0 = max(v0, eval(i - 1, 1, oldH));
        else
          v0 = max(v0, getSum(i - 1, oldH, h) + eval(i - 1, 0, oldH));
      }
      v1 = max(v1, v0);
      sol = max(sol, v1);
      dp[i][0].emplace_back(h, v0);
      dp[i][1].emplace_back(h, v1);
      // cout << i << ' ' << h << ' ' << v0 << ' ' << v1 << endl;
    }
  }
  return sol;
  /*for (int i = 1; i < N; ++i)
    for (int h = 0; h <= N; ++h) {
      // 1
      for (int oldH = h + 1; oldH <= N; ++oldH) {
        int lo = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h, INF)) -
                 onCol[i].begin();
        int up =
            upper_bound(onCol[i].begin(), onCol[i].end(), pair(oldH, INF)) -
            onCol[i].begin();
        dp[i][h][1] =
            max(dp[i][h][1], prefSum[i][up] - prefSum[i][lo] +
                                 max(dp[i - 1][oldH][0], dp[i - 1][oldH][1]));
      }
      // 0
      for (int oldH = 0; oldH <= N; ++oldH) {
        if (oldH >= h)
          dp[i][h][0] =
              max(dp[i][h][0], max(dp[i - 1][oldH][0], dp[i - 1][oldH][1]));
        else {
          int lo = upper_bound(onCol[i - 1].begin(), onCol[i - 1].end(),
                               pair(oldH, INF)) -
                   onCol[i - 1].begin();
          int up = upper_bound(onCol[i - 1].begin(), onCol[i - 1].end(),
                               pair(h, INF)) -
                   onCol[i - 1].begin();
          dp[i][h][0] =
              max(dp[i][h][0],
                  dp[i - 1][oldH][0] + prefSum[i - 1][up] - prefSum[i - 1][lo]);
        }
      }
      sol = max({sol, dp[i][h][0], dp[i][h][1]});
    }
  return sol;*/
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 22288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Execution timed out 1089 ms 27916 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 27748 KB Output is correct
2 Correct 41 ms 27684 KB Output is correct
3 Correct 80 ms 34372 KB Output is correct
4 Correct 78 ms 33996 KB Output is correct
5 Correct 124 ms 44236 KB Output is correct
6 Correct 120 ms 44028 KB Output is correct
7 Correct 146 ms 44072 KB Output is correct
8 Correct 112 ms 44064 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 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 5104 KB Output is correct
10 Correct 4 ms 5332 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 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 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 5104 KB Output is correct
10 Correct 4 ms 5332 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 20 ms 5280 KB Output is correct
17 Execution timed out 1082 ms 10952 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 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 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 5104 KB Output is correct
10 Correct 4 ms 5332 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 20 ms 5280 KB Output is correct
17 Execution timed out 1082 ms 10952 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 27748 KB Output is correct
2 Correct 41 ms 27684 KB Output is correct
3 Correct 80 ms 34372 KB Output is correct
4 Correct 78 ms 33996 KB Output is correct
5 Correct 124 ms 44236 KB Output is correct
6 Correct 120 ms 44028 KB Output is correct
7 Correct 146 ms 44072 KB Output is correct
8 Correct 112 ms 44064 KB Output is correct
9 Correct 153 ms 56656 KB Output is correct
10 Correct 81 ms 26528 KB Output is correct
11 Correct 177 ms 48236 KB Output is correct
12 Correct 3 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 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 42 ms 27596 KB Output is correct
19 Correct 43 ms 27624 KB Output is correct
20 Correct 43 ms 27652 KB Output is correct
21 Correct 44 ms 27736 KB Output is correct
22 Correct 176 ms 49944 KB Output is correct
23 Correct 236 ms 60504 KB Output is correct
24 Correct 230 ms 60724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 22288 KB Time limit exceeded
2 Halted 0 ms 0 KB -