답안 #1038904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038904 2024-07-30T08:51:58 Z juicy Bulldozer (JOI17_bulldozer) C++17
100 / 100
883 ms 35524 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e3 + 5;

int n;
int ptr[N];
array<int, 3> pt[N];
array<long long, 4> s[4 * N];

array<long long, 4> operator + (const array<long long, 4> &lt, const array<long long, 4> &rt) {
  return {max(lt[0], lt[2] + rt[0]), max(lt[1] + rt[2], rt[1]), lt[2] + rt[2], max({lt[3], rt[3], lt[1] + rt[0]})};
}

void bld(int id = 1, int l = 1, int r = n) {
  if (l == r) {
    s[id] = {pt[l][2], pt[l][2], pt[l][2], max(0, pt[l][2])};
    return;
  }
  int md = (l + r) / 2;
  bld(id * 2, l, md);
  bld(id * 2 + 1, md + 1, r);
  s[id] = s[id * 2] + s[id * 2 + 1];
}

void upd(int i, int x, int id = 1, int l = 1, int r = n) {
  if (l == r) {
    s[id] = {x, x, x, max(0, x)};
    return; 
  }
  int md = (l + r) / 2;
  if (i <= md) {
    upd(i, x, id * 2, l, md);
  } else {
    upd(i, x, id * 2 + 1, md + 1, r);
  }
  s[id] = s[id * 2] + s[id * 2 + 1];
} 

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> pt[i][j];
    }
  }
  sort(pt + 1, pt + n + 1);
  bld();
  vector<array<int, 4>> events;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      events.push_back({pt[j][1] - pt[i][1], pt[j][0] - pt[i][0], i, j});
    }
  }
  sort(events.begin(), events.end(), [&](const auto &a, const auto &b) {
    if ((long long) a[0] * b[1] == (long long) a[1] * b[0]) {
      return tie(a[2], a[3]) < tie(b[2], b[3]);
    }
    return (long long) a[0] * b[1] < (long long) a[1] * b[0];
  });
  iota(ptr + 1, ptr + n + 1, 1);
  auto res = s[1][3];
  for (int i = 0; i < events.size(); ++i) {
    int a = events[i][2], b = events[i][3];
    int &x = ptr[a], &y = ptr[b];
    upd(x, pt[b][2]);
    upd(y, pt[a][2]);
    swap(x, y);
    if (i + 1 == events.size() || (long long) events[i][0] * events[i + 1][1] != (long long) events[i + 1][0] * events[i][1]) {
      res = max(res, s[1][3]);
    }
  }
  cout << res;
  return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for (int i = 0; i < events.size(); ++i) {
      |                   ~~^~~~~~~~~~~~~~~
bulldozer.cpp:78:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     if (i + 1 == events.size() || (long long) events[i][0] * events[i + 1][1] != (long long) events[i + 1][0] * events[i][1]) {
      |         ~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 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 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 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 472 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 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 468 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 2 ms 604 KB Output is correct
7 Correct 2 ms 692 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 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 468 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 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 696 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 468 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 2 ms 604 KB Output is correct
7 Correct 2 ms 692 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 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 468 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 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 696 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 828 ms 33624 KB Output is correct
34 Correct 812 ms 33472 KB Output is correct
35 Correct 883 ms 33672 KB Output is correct
36 Correct 795 ms 33468 KB Output is correct
37 Correct 813 ms 33480 KB Output is correct
38 Correct 810 ms 33472 KB Output is correct
39 Correct 757 ms 33472 KB Output is correct
40 Correct 802 ms 33468 KB Output is correct
41 Correct 704 ms 33476 KB Output is correct
42 Correct 729 ms 33480 KB Output is correct
43 Correct 762 ms 33676 KB Output is correct
44 Correct 817 ms 33468 KB Output is correct
45 Correct 875 ms 33468 KB Output is correct
46 Correct 842 ms 33624 KB Output is correct
47 Correct 840 ms 33476 KB Output is correct
48 Correct 844 ms 33472 KB Output is correct
49 Correct 852 ms 33636 KB Output is correct
50 Correct 862 ms 33468 KB Output is correct
51 Correct 831 ms 33448 KB Output is correct
52 Correct 857 ms 33424 KB Output is correct
53 Correct 811 ms 33476 KB Output is correct
54 Correct 731 ms 33480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 468 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 2 ms 604 KB Output is correct
7 Correct 2 ms 692 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 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 468 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 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 2 ms 696 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 828 ms 33624 KB Output is correct
34 Correct 812 ms 33472 KB Output is correct
35 Correct 883 ms 33672 KB Output is correct
36 Correct 795 ms 33468 KB Output is correct
37 Correct 813 ms 33480 KB Output is correct
38 Correct 810 ms 33472 KB Output is correct
39 Correct 757 ms 33472 KB Output is correct
40 Correct 802 ms 33468 KB Output is correct
41 Correct 704 ms 33476 KB Output is correct
42 Correct 729 ms 33480 KB Output is correct
43 Correct 762 ms 33676 KB Output is correct
44 Correct 817 ms 33468 KB Output is correct
45 Correct 875 ms 33468 KB Output is correct
46 Correct 842 ms 33624 KB Output is correct
47 Correct 840 ms 33476 KB Output is correct
48 Correct 844 ms 33472 KB Output is correct
49 Correct 852 ms 33636 KB Output is correct
50 Correct 862 ms 33468 KB Output is correct
51 Correct 831 ms 33448 KB Output is correct
52 Correct 857 ms 33424 KB Output is correct
53 Correct 811 ms 33476 KB Output is correct
54 Correct 731 ms 33480 KB Output is correct
55 Correct 800 ms 33472 KB Output is correct
56 Correct 795 ms 35016 KB Output is correct
57 Correct 811 ms 33468 KB Output is correct
58 Correct 825 ms 33608 KB Output is correct
59 Correct 749 ms 33616 KB Output is correct
60 Correct 732 ms 33548 KB Output is correct
61 Correct 731 ms 33480 KB Output is correct
62 Correct 767 ms 35272 KB Output is correct
63 Correct 741 ms 33724 KB Output is correct
64 Correct 732 ms 34248 KB Output is correct
65 Correct 766 ms 33476 KB Output is correct
66 Correct 798 ms 33552 KB Output is correct
67 Correct 841 ms 33464 KB Output is correct
68 Correct 821 ms 33620 KB Output is correct
69 Correct 814 ms 33464 KB Output is correct
70 Correct 822 ms 33592 KB Output is correct
71 Correct 791 ms 33460 KB Output is correct
72 Correct 790 ms 33456 KB Output is correct
73 Correct 785 ms 33468 KB Output is correct
74 Correct 816 ms 33528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 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 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 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 472 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 468 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 692 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 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 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 468 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 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 600 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 2 ms 696 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 828 ms 33624 KB Output is correct
49 Correct 812 ms 33472 KB Output is correct
50 Correct 883 ms 33672 KB Output is correct
51 Correct 795 ms 33468 KB Output is correct
52 Correct 813 ms 33480 KB Output is correct
53 Correct 810 ms 33472 KB Output is correct
54 Correct 757 ms 33472 KB Output is correct
55 Correct 802 ms 33468 KB Output is correct
56 Correct 704 ms 33476 KB Output is correct
57 Correct 729 ms 33480 KB Output is correct
58 Correct 762 ms 33676 KB Output is correct
59 Correct 817 ms 33468 KB Output is correct
60 Correct 875 ms 33468 KB Output is correct
61 Correct 842 ms 33624 KB Output is correct
62 Correct 840 ms 33476 KB Output is correct
63 Correct 844 ms 33472 KB Output is correct
64 Correct 852 ms 33636 KB Output is correct
65 Correct 862 ms 33468 KB Output is correct
66 Correct 831 ms 33448 KB Output is correct
67 Correct 857 ms 33424 KB Output is correct
68 Correct 811 ms 33476 KB Output is correct
69 Correct 731 ms 33480 KB Output is correct
70 Correct 800 ms 33472 KB Output is correct
71 Correct 795 ms 35016 KB Output is correct
72 Correct 811 ms 33468 KB Output is correct
73 Correct 825 ms 33608 KB Output is correct
74 Correct 749 ms 33616 KB Output is correct
75 Correct 732 ms 33548 KB Output is correct
76 Correct 731 ms 33480 KB Output is correct
77 Correct 767 ms 35272 KB Output is correct
78 Correct 741 ms 33724 KB Output is correct
79 Correct 732 ms 34248 KB Output is correct
80 Correct 766 ms 33476 KB Output is correct
81 Correct 798 ms 33552 KB Output is correct
82 Correct 841 ms 33464 KB Output is correct
83 Correct 821 ms 33620 KB Output is correct
84 Correct 814 ms 33464 KB Output is correct
85 Correct 822 ms 33592 KB Output is correct
86 Correct 791 ms 33460 KB Output is correct
87 Correct 790 ms 33456 KB Output is correct
88 Correct 785 ms 33468 KB Output is correct
89 Correct 816 ms 33528 KB Output is correct
90 Correct 817 ms 33476 KB Output is correct
91 Correct 828 ms 33548 KB Output is correct
92 Correct 828 ms 33476 KB Output is correct
93 Correct 821 ms 33480 KB Output is correct
94 Correct 823 ms 33480 KB Output is correct
95 Correct 864 ms 33628 KB Output is correct
96 Correct 823 ms 33440 KB Output is correct
97 Correct 786 ms 33476 KB Output is correct
98 Correct 766 ms 33468 KB Output is correct
99 Correct 782 ms 33992 KB Output is correct
100 Correct 683 ms 35008 KB Output is correct
101 Correct 665 ms 33468 KB Output is correct
102 Correct 681 ms 33468 KB Output is correct
103 Correct 718 ms 34244 KB Output is correct
104 Correct 725 ms 33480 KB Output is correct
105 Correct 753 ms 34484 KB Output is correct
106 Correct 741 ms 34244 KB Output is correct
107 Correct 726 ms 33480 KB Output is correct
108 Correct 710 ms 33976 KB Output is correct
109 Correct 734 ms 34248 KB Output is correct
110 Correct 816 ms 35516 KB Output is correct
111 Correct 804 ms 33468 KB Output is correct
112 Correct 809 ms 33476 KB Output is correct
113 Correct 807 ms 33476 KB Output is correct
114 Correct 792 ms 34904 KB Output is correct
115 Correct 815 ms 33988 KB Output is correct
116 Correct 822 ms 34800 KB Output is correct
117 Correct 827 ms 35272 KB Output is correct
118 Correct 795 ms 34244 KB Output is correct
119 Correct 795 ms 34500 KB Output is correct
120 Correct 1 ms 344 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 812 ms 34500 KB Output is correct
123 Correct 818 ms 34760 KB Output is correct
124 Correct 791 ms 33988 KB Output is correct
125 Correct 789 ms 34760 KB Output is correct
126 Correct 805 ms 34948 KB Output is correct
127 Correct 883 ms 33732 KB Output is correct
128 Correct 828 ms 35524 KB Output is correct
129 Correct 832 ms 33732 KB Output is correct
130 Correct 872 ms 33908 KB Output is correct
131 Correct 851 ms 33992 KB Output is correct
132 Correct 851 ms 33992 KB Output is correct
133 Correct 824 ms 33984 KB Output is correct