답안 #891591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891591 2023-12-23T09:49:58 Z MilosMilutinovic Bulldozer (JOI17_bulldozer) C++14
5 / 100
1 ms 452 KB
// todo
#include <bits/stdc++.h>

using namespace std;

struct pt {
  int x, y;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n), w(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> w[i];
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    if (y[i] != y[j]) {
      return y[i] > y[j];
    } else {
      return x[i] > x[j];
    }
  });
  vector<long long> mx(4 * n);
  vector<long long> sum(4 * n);
  vector<long long> pref(4 * n);
  vector<long long> suff(4 * n);
  auto Pull = [&](int x) {
    sum[x] = sum[x << 1] + sum[x << 1 | 1];
    mx[x] = max({mx[x << 1], mx[x << 1 | 1], suff[x << 1] + pref[x << 1 | 1]});
    pref[x] = max(pref[x << 1], sum[x << 1] + pref[x << 1 | 1]);
    suff[x] = max(suff[x << 1 | 1], sum[x << 1 | 1] + suff[x << 1]);
  };
  function<void(int, int, int)> Build = [&](int x, int l, int r) {
    if (l == r) {
      sum[x] = w[order[l]];
      mx[x] = max(0LL, sum[x]);
      pref[x] = max(0LL, sum[x]);
      suff[x] = max(0LL, sum[x]);
      return;
    }
    int mid = l + r >> 1;
    Build(x << 1, l, mid);
    Build(x << 1 | 1, mid + 1, r);
    Pull(x);
  };  
  Build(1, 0, n - 1);
  /* vector<array<int, int, int, int>> swp;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      swp.emplace_back();
    }
  }
  sort(swp.begin(), swp.end(), [&](pair<int, int> a, pair<int, int> b) {

  }); */
  long long ans = mx[1];
  cout << ans << '\n';
  return 0;
}

Compilation message

bulldozer.cpp: In lambda function:
bulldozer.cpp:46:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -