답안 #1030925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030925 2024-07-22T12:19:57 Z tvladm2009 Bulldozer (JOI17_bulldozer) C++17
100 / 100
806 ms 50104 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;

const int N = 5e5 + 7;

struct Point {
    ll x;
    ll y;
    ll cost;
};

bool cmp(Point a, Point b) {
    return make_pair(a.x, a.y) < make_pair(b.x, b.y);
}

int n;
Point p[N];

struct Slope {
    ll y;
    ll x;
    int id1;
    int id2;
};

bool cmp_slope(Slope a, Slope b) {
    if (a.y * b.x == b.y * a.x) {
        return make_pair(a.id1, a.id2) < make_pair(b.id1, b.id2);
    }
    return a.y * b.x < b.y * a.x;
}

vector<Slope> v;
int pos[N];

struct Node {
    ll sum;
    ll pref;
    ll suff;
    ll ssm;
};

Node segt[4 * N];

Node operator + (Node a, Node b) {
    Node c;
    c.sum = a.sum + b.sum;
    c.pref = max(a.pref, a.sum + b.pref);
    c.suff = max(b.suff, b.sum + a.suff);
    c.ssm = max(a.ssm, b.ssm);
    c.ssm = max(c.ssm, a.suff + b.pref);
    return c;
}

void update(int v, int tl, int tr, int pos, int x) {
    if (tl == tr) {
        segt[v].sum = x;
        segt[v].pref = x;
        segt[v].suff = x;
        segt[v].ssm = x;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            update(2 * v, tl, tm, pos, x);
        } else {
            update(2 * v + 1, tm + 1, tr, pos, x);
        }
        segt[v] = segt[2 * v] + segt[2 * v + 1];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i].x >> p[i].y >> p[i].cost;
    }
    sort(p + 1, p + n + 1, cmp);

    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            Slope aux;
            aux.y = p[j].y - p[i].y;
            aux.x = p[j].x - p[i].x;
            aux.id1 = i;
            aux.id2 =j;
            v.push_back(aux);
        }
    }
    sort(v.begin(), v.end(), cmp_slope);

    for (int i = 1; i <= n; ++i) {
        pos[i] = i;
        update(1, 1, n, i, p[i].cost);
    }
    ll ans = max(0LL, segt[1].ssm);
    for (int i = 0; i < v.size(); ++i) {
        int j = i;
        while (j < v.size() && v[i].y * v[j].x == v[i].x * v[j].y) {
            update(1, 1, n, pos[v[j].id1], p[v[j].id2].cost);
            update(1, 1, n, pos[v[j].id2], p[v[j].id1].cost);
            swap(pos[v[j].id1], pos[v[j].id2]);
            j++;
        }
        ans = max(ans, segt[1].ssm);
        i = j - 1;
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Slope>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for (int i = 0; i < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
bulldozer.cpp:103:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Slope>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         while (j < v.size() && v[i].y * v[j].x == v[i].x * v[j].y) {
      |                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 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 640 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 604 KB Output is correct
10 Correct 1 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 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 856 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 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 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 2 ms 600 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 604 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 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 856 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 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 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 2 ms 600 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 604 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 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 792 ms 49860 KB Output is correct
34 Correct 802 ms 49824 KB Output is correct
35 Correct 777 ms 49824 KB Output is correct
36 Correct 766 ms 49824 KB Output is correct
37 Correct 761 ms 49848 KB Output is correct
38 Correct 769 ms 49772 KB Output is correct
39 Correct 767 ms 49768 KB Output is correct
40 Correct 750 ms 49760 KB Output is correct
41 Correct 756 ms 49976 KB Output is correct
42 Correct 718 ms 49824 KB Output is correct
43 Correct 716 ms 49800 KB Output is correct
44 Correct 763 ms 49828 KB Output is correct
45 Correct 745 ms 49916 KB Output is correct
46 Correct 755 ms 49852 KB Output is correct
47 Correct 734 ms 49808 KB Output is correct
48 Correct 707 ms 49856 KB Output is correct
49 Correct 695 ms 49792 KB Output is correct
50 Correct 687 ms 49824 KB Output is correct
51 Correct 683 ms 49800 KB Output is correct
52 Correct 671 ms 49824 KB Output is correct
53 Correct 737 ms 49824 KB Output is correct
54 Correct 736 ms 49912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 856 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 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 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 2 ms 600 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 604 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 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 792 ms 49860 KB Output is correct
34 Correct 802 ms 49824 KB Output is correct
35 Correct 777 ms 49824 KB Output is correct
36 Correct 766 ms 49824 KB Output is correct
37 Correct 761 ms 49848 KB Output is correct
38 Correct 769 ms 49772 KB Output is correct
39 Correct 767 ms 49768 KB Output is correct
40 Correct 750 ms 49760 KB Output is correct
41 Correct 756 ms 49976 KB Output is correct
42 Correct 718 ms 49824 KB Output is correct
43 Correct 716 ms 49800 KB Output is correct
44 Correct 763 ms 49828 KB Output is correct
45 Correct 745 ms 49916 KB Output is correct
46 Correct 755 ms 49852 KB Output is correct
47 Correct 734 ms 49808 KB Output is correct
48 Correct 707 ms 49856 KB Output is correct
49 Correct 695 ms 49792 KB Output is correct
50 Correct 687 ms 49824 KB Output is correct
51 Correct 683 ms 49800 KB Output is correct
52 Correct 671 ms 49824 KB Output is correct
53 Correct 737 ms 49824 KB Output is correct
54 Correct 736 ms 49912 KB Output is correct
55 Correct 738 ms 49824 KB Output is correct
56 Correct 690 ms 49968 KB Output is correct
57 Correct 702 ms 49968 KB Output is correct
58 Correct 695 ms 49804 KB Output is correct
59 Correct 684 ms 49824 KB Output is correct
60 Correct 685 ms 49836 KB Output is correct
61 Correct 699 ms 49848 KB Output is correct
62 Correct 694 ms 49852 KB Output is correct
63 Correct 714 ms 50104 KB Output is correct
64 Correct 763 ms 49824 KB Output is correct
65 Correct 677 ms 49840 KB Output is correct
66 Correct 688 ms 49736 KB Output is correct
67 Correct 689 ms 49844 KB Output is correct
68 Correct 691 ms 49848 KB Output is correct
69 Correct 721 ms 49864 KB Output is correct
70 Correct 728 ms 49892 KB Output is correct
71 Correct 685 ms 49764 KB Output is correct
72 Correct 705 ms 49836 KB Output is correct
73 Correct 694 ms 49840 KB Output is correct
74 Correct 686 ms 49824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 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 640 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 604 KB Output is correct
10 Correct 1 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 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 472 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 856 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 604 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 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 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 2 ms 600 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 604 KB Output is correct
43 Correct 2 ms 744 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 1 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 792 ms 49860 KB Output is correct
49 Correct 802 ms 49824 KB Output is correct
50 Correct 777 ms 49824 KB Output is correct
51 Correct 766 ms 49824 KB Output is correct
52 Correct 761 ms 49848 KB Output is correct
53 Correct 769 ms 49772 KB Output is correct
54 Correct 767 ms 49768 KB Output is correct
55 Correct 750 ms 49760 KB Output is correct
56 Correct 756 ms 49976 KB Output is correct
57 Correct 718 ms 49824 KB Output is correct
58 Correct 716 ms 49800 KB Output is correct
59 Correct 763 ms 49828 KB Output is correct
60 Correct 745 ms 49916 KB Output is correct
61 Correct 755 ms 49852 KB Output is correct
62 Correct 734 ms 49808 KB Output is correct
63 Correct 707 ms 49856 KB Output is correct
64 Correct 695 ms 49792 KB Output is correct
65 Correct 687 ms 49824 KB Output is correct
66 Correct 683 ms 49800 KB Output is correct
67 Correct 671 ms 49824 KB Output is correct
68 Correct 737 ms 49824 KB Output is correct
69 Correct 736 ms 49912 KB Output is correct
70 Correct 738 ms 49824 KB Output is correct
71 Correct 690 ms 49968 KB Output is correct
72 Correct 702 ms 49968 KB Output is correct
73 Correct 695 ms 49804 KB Output is correct
74 Correct 684 ms 49824 KB Output is correct
75 Correct 685 ms 49836 KB Output is correct
76 Correct 699 ms 49848 KB Output is correct
77 Correct 694 ms 49852 KB Output is correct
78 Correct 714 ms 50104 KB Output is correct
79 Correct 763 ms 49824 KB Output is correct
80 Correct 677 ms 49840 KB Output is correct
81 Correct 688 ms 49736 KB Output is correct
82 Correct 689 ms 49844 KB Output is correct
83 Correct 691 ms 49848 KB Output is correct
84 Correct 721 ms 49864 KB Output is correct
85 Correct 728 ms 49892 KB Output is correct
86 Correct 685 ms 49764 KB Output is correct
87 Correct 705 ms 49836 KB Output is correct
88 Correct 694 ms 49840 KB Output is correct
89 Correct 686 ms 49824 KB Output is correct
90 Correct 692 ms 49764 KB Output is correct
91 Correct 700 ms 49976 KB Output is correct
92 Correct 685 ms 49832 KB Output is correct
93 Correct 706 ms 49848 KB Output is correct
94 Correct 690 ms 49828 KB Output is correct
95 Correct 676 ms 49824 KB Output is correct
96 Correct 685 ms 49804 KB Output is correct
97 Correct 724 ms 49832 KB Output is correct
98 Correct 724 ms 49836 KB Output is correct
99 Correct 692 ms 49824 KB Output is correct
100 Correct 534 ms 49848 KB Output is correct
101 Correct 543 ms 49836 KB Output is correct
102 Correct 561 ms 49824 KB Output is correct
103 Correct 537 ms 49848 KB Output is correct
104 Correct 528 ms 49824 KB Output is correct
105 Correct 582 ms 49980 KB Output is correct
106 Correct 572 ms 49824 KB Output is correct
107 Correct 628 ms 49824 KB Output is correct
108 Correct 583 ms 49848 KB Output is correct
109 Correct 597 ms 49836 KB Output is correct
110 Correct 685 ms 49824 KB Output is correct
111 Correct 619 ms 49856 KB Output is correct
112 Correct 623 ms 49892 KB Output is correct
113 Correct 619 ms 49848 KB Output is correct
114 Correct 627 ms 49856 KB Output is correct
115 Correct 628 ms 49944 KB Output is correct
116 Correct 670 ms 49840 KB Output is correct
117 Correct 632 ms 49824 KB Output is correct
118 Correct 689 ms 49920 KB Output is correct
119 Correct 738 ms 49824 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 806 ms 49856 KB Output is correct
123 Correct 758 ms 49848 KB Output is correct
124 Correct 761 ms 49824 KB Output is correct
125 Correct 753 ms 50048 KB Output is correct
126 Correct 764 ms 49848 KB Output is correct
127 Correct 787 ms 49856 KB Output is correct
128 Correct 774 ms 49824 KB Output is correct
129 Correct 757 ms 49844 KB Output is correct
130 Correct 762 ms 49820 KB Output is correct
131 Correct 770 ms 49848 KB Output is correct
132 Correct 768 ms 49824 KB Output is correct
133 Correct 754 ms 49768 KB Output is correct