답안 #659610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659610 2022-11-18T18:08:03 Z peijar 메기 농장 (IOI22_fish) C++17
37 / 100
1000 ms 31300 KB
#include "fish.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e18;

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());
  }
  array<vector<pair<int, int>>, 2> oldDp, suffixMax;
  for (int i = 0; i < 2; ++i) {
    for (int x : interesting[0]) {
      oldDp[i].emplace_back(x, 0);
      suffixMax[i].emplace_back(x, 0);
    }
  }

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

  auto getSum = [&](int i, int h1, int h2) -> int {
    if (h1 > h2)
      return 0;
    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();
    vector<pair<int, int>> dp0, dp1;
    int curOld = 0;
    int cntBefore = interesting[i - 1].size();
    vector<int> prevI(cntBefore);
    int curPos = 0;
    int curSum = 0;
    for (int jHauteur = 0; jHauteur < cntBefore; ++jHauteur) {
      int oldH = interesting[i - 1][jHauteur];
      prevI[jHauteur] = oldDp[1][jHauteur].second;
      while (curPos < (int)onCol[i].size() and onCol[i][curPos].first <= oldH)
        curSum += onCol[i][curPos++].second;
      assert(curSum == getSum(i, 0, oldH));
      prevI[jHauteur] += curSum;
    }
    for (int j = cntBefore - 2; j >= 0; --j)
      prevI[j] = max(prevI[j], prevI[j + 1]);

    for (int iHauteur = 0; iHauteur < nbInteressants; ++iHauteur) {
      int h = interesting[i][iHauteur];
      // 1
      int v1 = 0;
      int v0 = 0;
      while (curOld < cntBefore and interesting[i - 1][curOld] <= h)
        ++curOld;
      assert(curOld);
      v0 = suffixMax[1][curOld - 1].second;
      if (curOld < cntBefore)
        v1 = max(v1, prevI[curOld] - getSum(i, 0, h));
      for (int jHauteur = 0; jHauteur < cntBefore; ++jHauteur) {
        int oldH = interesting[i - 1][jHauteur];
        // if (oldH > h)
        // v1 = max(v1, getSum(i, h, oldH) + eval(1, oldH));
        if (oldH < h)
          v0 = max(v0, getSum(i - 1, oldH, h) + eval(0, oldH));
      }
      v1 = max(v1, v0);
      sol = max(sol, v1);
      dp0.emplace_back(h, v0);
      dp1.emplace_back(h, v1);
      // cout << i << ' ' << h << ' ' << v0 << ' ' << v1 << endl;
    }
    oldDp[0] = move(dp0);
    oldDp[1] = move(dp1);
    suffixMax[0] = oldDp[0];
    suffixMax[1] = oldDp[1];
    for (int h = nbInteressants - 2; h >= 0; --h)
      for (int side = 0; side < 2; ++side)
        suffixMax[side][h].second =
            max(suffixMax[side][h].second, suffixMax[side][h + 1].second);
  }
  return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 25276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1093 ms 31300 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 13524 KB Output is correct
2 Correct 38 ms 13600 KB Output is correct
3 Correct 73 ms 17484 KB Output is correct
4 Correct 68 ms 17228 KB Output is correct
5 Correct 109 ms 23756 KB Output is correct
6 Correct 105 ms 23720 KB Output is correct
7 Correct 113 ms 23748 KB Output is correct
8 Correct 101 ms 23744 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 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 9 ms 468 KB Output is correct
17 Correct 728 ms 4376 KB Output is correct
18 Correct 621 ms 4576 KB Output is correct
19 Correct 349 ms 4180 KB Output is correct
20 Correct 274 ms 4300 KB Output is correct
21 Correct 263 ms 4204 KB Output is correct
22 Execution timed out 1065 ms 8176 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 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 9 ms 468 KB Output is correct
17 Correct 728 ms 4376 KB Output is correct
18 Correct 621 ms 4576 KB Output is correct
19 Correct 349 ms 4180 KB Output is correct
20 Correct 274 ms 4300 KB Output is correct
21 Correct 263 ms 4204 KB Output is correct
22 Execution timed out 1065 ms 8176 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 13524 KB Output is correct
2 Correct 38 ms 13600 KB Output is correct
3 Correct 73 ms 17484 KB Output is correct
4 Correct 68 ms 17228 KB Output is correct
5 Correct 109 ms 23756 KB Output is correct
6 Correct 105 ms 23720 KB Output is correct
7 Correct 113 ms 23748 KB Output is correct
8 Correct 101 ms 23744 KB Output is correct
9 Correct 134 ms 23752 KB Output is correct
10 Correct 74 ms 14012 KB Output is correct
11 Correct 166 ms 27864 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 1 ms 276 KB Output is correct
18 Correct 43 ms 13568 KB Output is correct
19 Correct 40 ms 13592 KB Output is correct
20 Correct 40 ms 13588 KB Output is correct
21 Correct 40 ms 13600 KB Output is correct
22 Correct 149 ms 21960 KB Output is correct
23 Correct 203 ms 27932 KB Output is correct
24 Correct 200 ms 27944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 25276 KB Time limit exceeded
2 Halted 0 ms 0 KB -