답안 #471116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471116 2021-09-07T07:05:11 Z gs18103 Bulldozer (JOI17_bulldozer) C++14
100 / 100
809 ms 33496 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 1010;
const int INF = 1e9;
const ll LINF = 9e18;

class SegmentTree {
    struct Node {
        ll lmx = 0, rmx = 0, mx = 0, s = 0;
        Node operator + (Node b) {
            Node ret;
            ret.lmx = max(lmx, s + b.lmx);
            ret.rmx = max(b.rmx, b.s + rmx);
            ret.mx = max({mx, b.mx, rmx + b.lmx});
            ret.s = s + b.s;
            return ret;
        }
    };
    vector <Node> tree;
    int sz;
public:

    void Init(int n) {
        tree.resize(4*n+10);
        sz = n;
    }

    void Update(int k, ll val) {
        update(1, 0, sz-1, k, val);
    }
    void update(int node, int s, int e, int k, ll val) {
        if(s == e) {
            tree[node].lmx = tree[node].rmx = tree[node].mx = max(0LL, val);
            tree[node].s = val;
            return;
        }
        int m = s + e >> 1;
        if(k <= m) update(node<<1, s, m, k, val);
        else update(node<<1|1, m+1, e, k, val);
        tree[node] = tree[node<<1] + tree[node<<1|1];
    }

    ll get() {
        return tree[1].mx;
    }
};

struct Point {
    int x, y;
    ll val;
    bool operator < (const Point &p) const {
        return pii(x, y) < pii(p.x, p.y);
    }
};

struct Evt{
	int dx, dy, idx1, idx2;
    Evt(int dx, int dy, int idx1, int idx2) : dx(dx), dy(dy), idx1(idx1), idx2(idx2) {}
	bool operator < (const Evt &s)const{
		ll k = 1ll * dx * s.dy - 1ll * dy * s.dx;
		if(k == 0) return pii(idx1, idx2) < pii(s.idx1, s.idx2);
        return k > 0;
	}
};

ll ccw(Evt a, Evt b) {
    return (ll)a.dx * b.dy - (ll)b.dx * a.dy;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n;
    cin >> n;
    vector <Point> a(n);
    vector <int> pos(n);

    for(int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y >> a[i].val;
    }

    if(n == 1) {
        cout << max(0LL, a[0].val) << endl;
        return 0;
    }
    sort(all(a));
    for(int i = 0; i < n; i++) {
        pos[i] = i;
    }

    vector <Evt> line;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            line.eb(a[j].x - a[i].x, a[j].y - a[i].y, i, j);
        }
    }
    sort(all(line));

    SegmentTree ST;
    ST.Init(n);
    for(int i = 0; i < n; i++) {
        ST.Update(i, a[i].val);
    }

    ll ans = 0;
    for(int i = 0; i < line.size(); i++) {
        int rx = pos[line[i].idx1], ry = pos[line[i].idx2];
        swap(a[rx], a[ry]);
        swap(pos[line[i].idx1], pos[line[i].idx2]);
        ST.Update(rx, a[rx].val);
        ST.Update(ry, a[ry].val);
        if(i + 1 < line.size() && ccw(line[i], line[i+1]) == 0) continue;
        ans = max(ans, ST.get());
    }
    cout << ans << endl;
}

Compilation message

bulldozer.cpp: In member function 'void SegmentTree::update(int, int, int, int, ll)':
bulldozer.cpp:48:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |         int m = s + e >> 1;
      |                 ~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Evt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     for(int i = 0; i < line.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
bulldozer.cpp:123:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Evt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |         if(i + 1 < line.size() && ccw(line[i], line[i+1]) == 0) continue;
      |            ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 781 ms 33352 KB Output is correct
34 Correct 785 ms 33320 KB Output is correct
35 Correct 801 ms 33440 KB Output is correct
36 Correct 798 ms 33328 KB Output is correct
37 Correct 794 ms 33376 KB Output is correct
38 Correct 773 ms 33328 KB Output is correct
39 Correct 781 ms 33304 KB Output is correct
40 Correct 793 ms 33328 KB Output is correct
41 Correct 777 ms 33328 KB Output is correct
42 Correct 785 ms 33340 KB Output is correct
43 Correct 776 ms 33320 KB Output is correct
44 Correct 782 ms 33328 KB Output is correct
45 Correct 809 ms 33304 KB Output is correct
46 Correct 771 ms 33420 KB Output is correct
47 Correct 778 ms 33312 KB Output is correct
48 Correct 781 ms 33328 KB Output is correct
49 Correct 781 ms 33316 KB Output is correct
50 Correct 773 ms 33328 KB Output is correct
51 Correct 775 ms 33328 KB Output is correct
52 Correct 781 ms 33328 KB Output is correct
53 Correct 797 ms 33324 KB Output is correct
54 Correct 780 ms 33328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 781 ms 33352 KB Output is correct
34 Correct 785 ms 33320 KB Output is correct
35 Correct 801 ms 33440 KB Output is correct
36 Correct 798 ms 33328 KB Output is correct
37 Correct 794 ms 33376 KB Output is correct
38 Correct 773 ms 33328 KB Output is correct
39 Correct 781 ms 33304 KB Output is correct
40 Correct 793 ms 33328 KB Output is correct
41 Correct 777 ms 33328 KB Output is correct
42 Correct 785 ms 33340 KB Output is correct
43 Correct 776 ms 33320 KB Output is correct
44 Correct 782 ms 33328 KB Output is correct
45 Correct 809 ms 33304 KB Output is correct
46 Correct 771 ms 33420 KB Output is correct
47 Correct 778 ms 33312 KB Output is correct
48 Correct 781 ms 33328 KB Output is correct
49 Correct 781 ms 33316 KB Output is correct
50 Correct 773 ms 33328 KB Output is correct
51 Correct 775 ms 33328 KB Output is correct
52 Correct 781 ms 33328 KB Output is correct
53 Correct 797 ms 33324 KB Output is correct
54 Correct 780 ms 33328 KB Output is correct
55 Correct 786 ms 33348 KB Output is correct
56 Correct 789 ms 33396 KB Output is correct
57 Correct 807 ms 33392 KB Output is correct
58 Correct 800 ms 33328 KB Output is correct
59 Correct 809 ms 33396 KB Output is correct
60 Correct 798 ms 33308 KB Output is correct
61 Correct 798 ms 33408 KB Output is correct
62 Correct 796 ms 33352 KB Output is correct
63 Correct 802 ms 33316 KB Output is correct
64 Correct 799 ms 33316 KB Output is correct
65 Correct 778 ms 33304 KB Output is correct
66 Correct 784 ms 33328 KB Output is correct
67 Correct 784 ms 33328 KB Output is correct
68 Correct 786 ms 33316 KB Output is correct
69 Correct 785 ms 33304 KB Output is correct
70 Correct 800 ms 33304 KB Output is correct
71 Correct 781 ms 33320 KB Output is correct
72 Correct 795 ms 33328 KB Output is correct
73 Correct 800 ms 33328 KB Output is correct
74 Correct 796 ms 33288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 312 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 781 ms 33352 KB Output is correct
49 Correct 785 ms 33320 KB Output is correct
50 Correct 801 ms 33440 KB Output is correct
51 Correct 798 ms 33328 KB Output is correct
52 Correct 794 ms 33376 KB Output is correct
53 Correct 773 ms 33328 KB Output is correct
54 Correct 781 ms 33304 KB Output is correct
55 Correct 793 ms 33328 KB Output is correct
56 Correct 777 ms 33328 KB Output is correct
57 Correct 785 ms 33340 KB Output is correct
58 Correct 776 ms 33320 KB Output is correct
59 Correct 782 ms 33328 KB Output is correct
60 Correct 809 ms 33304 KB Output is correct
61 Correct 771 ms 33420 KB Output is correct
62 Correct 778 ms 33312 KB Output is correct
63 Correct 781 ms 33328 KB Output is correct
64 Correct 781 ms 33316 KB Output is correct
65 Correct 773 ms 33328 KB Output is correct
66 Correct 775 ms 33328 KB Output is correct
67 Correct 781 ms 33328 KB Output is correct
68 Correct 797 ms 33324 KB Output is correct
69 Correct 780 ms 33328 KB Output is correct
70 Correct 786 ms 33348 KB Output is correct
71 Correct 789 ms 33396 KB Output is correct
72 Correct 807 ms 33392 KB Output is correct
73 Correct 800 ms 33328 KB Output is correct
74 Correct 809 ms 33396 KB Output is correct
75 Correct 798 ms 33308 KB Output is correct
76 Correct 798 ms 33408 KB Output is correct
77 Correct 796 ms 33352 KB Output is correct
78 Correct 802 ms 33316 KB Output is correct
79 Correct 799 ms 33316 KB Output is correct
80 Correct 778 ms 33304 KB Output is correct
81 Correct 784 ms 33328 KB Output is correct
82 Correct 784 ms 33328 KB Output is correct
83 Correct 786 ms 33316 KB Output is correct
84 Correct 785 ms 33304 KB Output is correct
85 Correct 800 ms 33304 KB Output is correct
86 Correct 781 ms 33320 KB Output is correct
87 Correct 795 ms 33328 KB Output is correct
88 Correct 800 ms 33328 KB Output is correct
89 Correct 796 ms 33288 KB Output is correct
90 Correct 785 ms 33296 KB Output is correct
91 Correct 788 ms 33356 KB Output is correct
92 Correct 788 ms 33300 KB Output is correct
93 Correct 772 ms 33496 KB Output is correct
94 Correct 794 ms 33328 KB Output is correct
95 Correct 789 ms 33304 KB Output is correct
96 Correct 791 ms 33328 KB Output is correct
97 Correct 787 ms 33392 KB Output is correct
98 Correct 793 ms 33328 KB Output is correct
99 Correct 786 ms 33320 KB Output is correct
100 Correct 593 ms 33308 KB Output is correct
101 Correct 613 ms 33320 KB Output is correct
102 Correct 598 ms 33328 KB Output is correct
103 Correct 610 ms 33328 KB Output is correct
104 Correct 580 ms 33404 KB Output is correct
105 Correct 643 ms 33352 KB Output is correct
106 Correct 644 ms 33328 KB Output is correct
107 Correct 629 ms 33328 KB Output is correct
108 Correct 639 ms 33284 KB Output is correct
109 Correct 635 ms 33316 KB Output is correct
110 Correct 711 ms 33316 KB Output is correct
111 Correct 711 ms 33372 KB Output is correct
112 Correct 715 ms 33296 KB Output is correct
113 Correct 714 ms 33324 KB Output is correct
114 Correct 733 ms 33304 KB Output is correct
115 Correct 711 ms 33312 KB Output is correct
116 Correct 734 ms 33320 KB Output is correct
117 Correct 725 ms 33316 KB Output is correct
118 Correct 711 ms 33316 KB Output is correct
119 Correct 716 ms 33316 KB Output is correct
120 Correct 1 ms 308 KB Output is correct
121 Correct 0 ms 204 KB Output is correct
122 Correct 787 ms 33320 KB Output is correct
123 Correct 796 ms 33316 KB Output is correct
124 Correct 787 ms 33376 KB Output is correct
125 Correct 781 ms 33388 KB Output is correct
126 Correct 769 ms 33328 KB Output is correct
127 Correct 794 ms 33344 KB Output is correct
128 Correct 775 ms 33328 KB Output is correct
129 Correct 791 ms 33320 KB Output is correct
130 Correct 773 ms 33368 KB Output is correct
131 Correct 773 ms 33456 KB Output is correct
132 Correct 777 ms 33328 KB Output is correct
133 Correct 796 ms 33328 KB Output is correct