Submission #892516

# Submission time Handle Problem Language Result Execution time Memory
892516 2023-12-25T13:02:21 Z MilosMilutinovic Bulldozer (JOI17_bulldozer) C++14
55 / 100
989 ms 65952 KB
#include <bits/stdc++.h>
 
using namespace std;
 
struct pt {
  int x, y;
};
 
bool same(int x1, int y1, int x2, int y2) {
  // y1 / x1 = y2 / x2
  return x1 * 1LL * y2 == y1 * 1LL * x2;
}

long long cross(pt a, pt b) {
  return a.x * 1LL * b.y - a.y * 1LL * b.x;
}

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<int> pos(n);
  for (int i = 0; i < n; i++) {
    pos[order[i]] = i;
  }
  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);
  };
  function<void(int, int, int, int)> Update = [&](int x, int l, int r, int p) {
    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;
    if (p <= mid) {
      Update(x << 1, l, mid, p);
    } else {
      Update(x << 1 | 1, mid + 1, r, p);
    }
    Pull(x);
  };
  Build(1, 0, n - 1);
  vector<array<int, 4>> qs;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int fx = x[j] - x[i];
      int fy = y[j] - y[i];
      if (fy < 0 || (fy == 0 && fx < 0)) {
        fx = -fx;
        fy = -fy;
      }
      qs.push_back({fx, fy, i, j});
    }
  }
  sort(qs.begin(), qs.end(), [&](array<int, 4> a, array<int, 4> b) {
    pt p;
    p.x = a[0];
    p.y = a[1];
    pt q;
    q.x = b[0];
    q.y = b[1];
    return cross(p, q) >= 0;
  });
  int sz = (int) qs.size();
  long long ans = mx[1];
  for (int i = 0; i < sz; i++) {
    int ptr = i;
    while (ptr < sz && same(qs[i][0], qs[i][1], qs[ptr][0], qs[ptr][1])) {
      swap(order[pos[qs[ptr][2]]], order[pos[qs[ptr][3]]]);
      swap(pos[qs[ptr][2]], pos[qs[ptr][3]]);
      Update(1, 0, n - 1, pos[qs[ptr][2]]);
      Update(1, 0, n - 1, pos[qs[ptr][3]]);
      ptr += 1;
    }
    ans = max(ans, mx[1]);
    i = ptr - 1;
  }
  cout << ans << '\n';
  return 0;
}

Compilation message

bulldozer.cpp: In lambda function:
bulldozer.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |     int mid = l + r >> 1;
      |               ~~^~~
bulldozer.cpp: In lambda function:
bulldozer.cpp:71:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 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 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 688 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 680 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 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 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 688 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 680 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 951 ms 34752 KB Output is correct
34 Correct 937 ms 34748 KB Output is correct
35 Correct 946 ms 34940 KB Output is correct
36 Correct 934 ms 35252 KB Output is correct
37 Correct 942 ms 34240 KB Output is correct
38 Correct 971 ms 34236 KB Output is correct
39 Correct 983 ms 33756 KB Output is correct
40 Correct 981 ms 35076 KB Output is correct
41 Correct 980 ms 33924 KB Output is correct
42 Correct 986 ms 33984 KB Output is correct
43 Correct 969 ms 35708 KB Output is correct
44 Correct 961 ms 33736 KB Output is correct
45 Correct 989 ms 34236 KB Output is correct
46 Correct 980 ms 34568 KB Output is correct
47 Correct 946 ms 34260 KB Output is correct
48 Correct 948 ms 33872 KB Output is correct
49 Correct 975 ms 34628 KB Output is correct
50 Correct 967 ms 34240 KB Output is correct
51 Correct 955 ms 35384 KB Output is correct
52 Correct 949 ms 34752 KB Output is correct
53 Correct 980 ms 34356 KB Output is correct
54 Correct 944 ms 35264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 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 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 688 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 680 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 951 ms 34752 KB Output is correct
34 Correct 937 ms 34748 KB Output is correct
35 Correct 946 ms 34940 KB Output is correct
36 Correct 934 ms 35252 KB Output is correct
37 Correct 942 ms 34240 KB Output is correct
38 Correct 971 ms 34236 KB Output is correct
39 Correct 983 ms 33756 KB Output is correct
40 Correct 981 ms 35076 KB Output is correct
41 Correct 980 ms 33924 KB Output is correct
42 Correct 986 ms 33984 KB Output is correct
43 Correct 969 ms 35708 KB Output is correct
44 Correct 961 ms 33736 KB Output is correct
45 Correct 989 ms 34236 KB Output is correct
46 Correct 980 ms 34568 KB Output is correct
47 Correct 946 ms 34260 KB Output is correct
48 Correct 948 ms 33872 KB Output is correct
49 Correct 975 ms 34628 KB Output is correct
50 Correct 967 ms 34240 KB Output is correct
51 Correct 955 ms 35384 KB Output is correct
52 Correct 949 ms 34752 KB Output is correct
53 Correct 980 ms 34356 KB Output is correct
54 Correct 944 ms 35264 KB Output is correct
55 Correct 962 ms 35008 KB Output is correct
56 Correct 963 ms 34748 KB Output is correct
57 Correct 972 ms 34236 KB Output is correct
58 Correct 943 ms 34380 KB Output is correct
59 Correct 942 ms 34748 KB Output is correct
60 Correct 931 ms 33980 KB Output is correct
61 Correct 936 ms 34996 KB Output is correct
62 Correct 945 ms 34164 KB Output is correct
63 Correct 937 ms 35520 KB Output is correct
64 Correct 938 ms 34236 KB Output is correct
65 Runtime error 231 ms 65952 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -