Submission #892526

# Submission time Handle Problem Language Result Execution time Memory
892526 2023-12-25T13:11:56 Z MilosMilutinovic Bulldozer (JOI17_bulldozer) C++14
100 / 100
996 ms 35652 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 i = order[_i];
      int j = order[_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];
    if (cross(p, q) == 0) {
      return make_pair(pos[a[2]], pos[a[3]]) < make_pair(pos[b[2]], pos[b[3]]);
    }
    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 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 456 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 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 3 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 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 0 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 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 3 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 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 0 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 972 ms 35264 KB Output is correct
34 Correct 953 ms 35008 KB Output is correct
35 Correct 950 ms 34992 KB Output is correct
36 Correct 948 ms 34752 KB Output is correct
37 Correct 960 ms 35260 KB Output is correct
38 Correct 973 ms 33808 KB Output is correct
39 Correct 941 ms 34740 KB Output is correct
40 Correct 934 ms 35260 KB Output is correct
41 Correct 948 ms 35504 KB Output is correct
42 Correct 933 ms 34752 KB Output is correct
43 Correct 929 ms 35504 KB Output is correct
44 Correct 928 ms 35264 KB Output is correct
45 Correct 933 ms 34496 KB Output is correct
46 Correct 929 ms 35292 KB Output is correct
47 Correct 937 ms 35520 KB Output is correct
48 Correct 942 ms 35520 KB Output is correct
49 Correct 974 ms 34748 KB Output is correct
50 Correct 942 ms 35260 KB Output is correct
51 Correct 933 ms 34752 KB Output is correct
52 Correct 928 ms 33728 KB Output is correct
53 Correct 936 ms 34240 KB Output is correct
54 Correct 935 ms 33980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 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 3 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 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 0 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 972 ms 35264 KB Output is correct
34 Correct 953 ms 35008 KB Output is correct
35 Correct 950 ms 34992 KB Output is correct
36 Correct 948 ms 34752 KB Output is correct
37 Correct 960 ms 35260 KB Output is correct
38 Correct 973 ms 33808 KB Output is correct
39 Correct 941 ms 34740 KB Output is correct
40 Correct 934 ms 35260 KB Output is correct
41 Correct 948 ms 35504 KB Output is correct
42 Correct 933 ms 34752 KB Output is correct
43 Correct 929 ms 35504 KB Output is correct
44 Correct 928 ms 35264 KB Output is correct
45 Correct 933 ms 34496 KB Output is correct
46 Correct 929 ms 35292 KB Output is correct
47 Correct 937 ms 35520 KB Output is correct
48 Correct 942 ms 35520 KB Output is correct
49 Correct 974 ms 34748 KB Output is correct
50 Correct 942 ms 35260 KB Output is correct
51 Correct 933 ms 34752 KB Output is correct
52 Correct 928 ms 33728 KB Output is correct
53 Correct 936 ms 34240 KB Output is correct
54 Correct 935 ms 33980 KB Output is correct
55 Correct 938 ms 35520 KB Output is correct
56 Correct 934 ms 34496 KB Output is correct
57 Correct 936 ms 35652 KB Output is correct
58 Correct 936 ms 35004 KB Output is correct
59 Correct 939 ms 33976 KB Output is correct
60 Correct 947 ms 35516 KB Output is correct
61 Correct 946 ms 35060 KB Output is correct
62 Correct 937 ms 35520 KB Output is correct
63 Correct 948 ms 35008 KB Output is correct
64 Correct 937 ms 33728 KB Output is correct
65 Correct 937 ms 35516 KB Output is correct
66 Correct 945 ms 35008 KB Output is correct
67 Correct 940 ms 33716 KB Output is correct
68 Correct 933 ms 35264 KB Output is correct
69 Correct 969 ms 34232 KB Output is correct
70 Correct 937 ms 33984 KB Output is correct
71 Correct 943 ms 33728 KB Output is correct
72 Correct 996 ms 35004 KB Output is correct
73 Correct 932 ms 33984 KB Output is correct
74 Correct 966 ms 35520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 456 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 680 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 3 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 600 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 972 ms 35264 KB Output is correct
49 Correct 953 ms 35008 KB Output is correct
50 Correct 950 ms 34992 KB Output is correct
51 Correct 948 ms 34752 KB Output is correct
52 Correct 960 ms 35260 KB Output is correct
53 Correct 973 ms 33808 KB Output is correct
54 Correct 941 ms 34740 KB Output is correct
55 Correct 934 ms 35260 KB Output is correct
56 Correct 948 ms 35504 KB Output is correct
57 Correct 933 ms 34752 KB Output is correct
58 Correct 929 ms 35504 KB Output is correct
59 Correct 928 ms 35264 KB Output is correct
60 Correct 933 ms 34496 KB Output is correct
61 Correct 929 ms 35292 KB Output is correct
62 Correct 937 ms 35520 KB Output is correct
63 Correct 942 ms 35520 KB Output is correct
64 Correct 974 ms 34748 KB Output is correct
65 Correct 942 ms 35260 KB Output is correct
66 Correct 933 ms 34752 KB Output is correct
67 Correct 928 ms 33728 KB Output is correct
68 Correct 936 ms 34240 KB Output is correct
69 Correct 935 ms 33980 KB Output is correct
70 Correct 938 ms 35520 KB Output is correct
71 Correct 934 ms 34496 KB Output is correct
72 Correct 936 ms 35652 KB Output is correct
73 Correct 936 ms 35004 KB Output is correct
74 Correct 939 ms 33976 KB Output is correct
75 Correct 947 ms 35516 KB Output is correct
76 Correct 946 ms 35060 KB Output is correct
77 Correct 937 ms 35520 KB Output is correct
78 Correct 948 ms 35008 KB Output is correct
79 Correct 937 ms 33728 KB Output is correct
80 Correct 937 ms 35516 KB Output is correct
81 Correct 945 ms 35008 KB Output is correct
82 Correct 940 ms 33716 KB Output is correct
83 Correct 933 ms 35264 KB Output is correct
84 Correct 969 ms 34232 KB Output is correct
85 Correct 937 ms 33984 KB Output is correct
86 Correct 943 ms 33728 KB Output is correct
87 Correct 996 ms 35004 KB Output is correct
88 Correct 932 ms 33984 KB Output is correct
89 Correct 966 ms 35520 KB Output is correct
90 Correct 936 ms 34236 KB Output is correct
91 Correct 954 ms 35008 KB Output is correct
92 Correct 940 ms 35516 KB Output is correct
93 Correct 948 ms 35624 KB Output is correct
94 Correct 945 ms 33728 KB Output is correct
95 Correct 937 ms 35252 KB Output is correct
96 Correct 939 ms 35632 KB Output is correct
97 Correct 940 ms 34484 KB Output is correct
98 Correct 938 ms 34236 KB Output is correct
99 Correct 947 ms 35296 KB Output is correct
100 Correct 898 ms 34752 KB Output is correct
101 Correct 911 ms 33908 KB Output is correct
102 Correct 906 ms 34752 KB Output is correct
103 Correct 886 ms 35508 KB Output is correct
104 Correct 942 ms 33744 KB Output is correct
105 Correct 956 ms 35052 KB Output is correct
106 Correct 953 ms 34508 KB Output is correct
107 Correct 951 ms 35380 KB Output is correct
108 Correct 930 ms 34876 KB Output is correct
109 Correct 969 ms 35484 KB Output is correct
110 Correct 986 ms 34412 KB Output is correct
111 Correct 967 ms 33724 KB Output is correct
112 Correct 956 ms 35520 KB Output is correct
113 Correct 953 ms 35520 KB Output is correct
114 Correct 963 ms 35264 KB Output is correct
115 Correct 917 ms 34744 KB Output is correct
116 Correct 917 ms 35512 KB Output is correct
117 Correct 922 ms 34744 KB Output is correct
118 Correct 919 ms 34752 KB Output is correct
119 Correct 911 ms 35508 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 948 ms 34480 KB Output is correct
123 Correct 943 ms 35516 KB Output is correct
124 Correct 941 ms 35008 KB Output is correct
125 Correct 960 ms 34700 KB Output is correct
126 Correct 933 ms 34496 KB Output is correct
127 Correct 933 ms 34496 KB Output is correct
128 Correct 957 ms 34740 KB Output is correct
129 Correct 938 ms 33980 KB Output is correct
130 Correct 935 ms 35112 KB Output is correct
131 Correct 941 ms 35008 KB Output is correct
132 Correct 937 ms 34496 KB Output is correct
133 Correct 934 ms 34224 KB Output is correct