답안 #401918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401918 2021-05-11T01:45:33 Z timmyfeng Bulldozer (JOI17_bulldozer) C++17
100 / 100
976 ms 50124 KB
#include <bits/stdc++.h>
using namespace std;

using point = complex<long long>;
#define X real()
#define Y imag()

const int N = 2000;

struct segtree {
    segtree *left = nullptr, *right = nullptr;
    long long prefix = 0, suffix = 0, sum = 0, maxi = 0;

    void update(int a, int x, int l, int r) {
        if (l == r) {
            prefix = suffix = maxi = max(0, x);
            sum = x;
        } else {
            if (!left) {
                left = new segtree();
                right = new segtree();
            }

            int m = (l + r) / 2;
            if (a <= m) {
                left->update(a, x, l, m);
            } else {
                right->update(a, x, m + 1, r);
            }

            prefix = max(left->prefix, left->sum + right->prefix);
            suffix = max(left->suffix + right->sum, right->suffix);
            sum = left->sum + right->sum;
            maxi = max({left->maxi, right->maxi, left->suffix + right->prefix});
        }
    }
};

long long cross(point a, point b) {
    return a.X * b.Y - a.Y * b.X;
}

bool comp(point a, point b) {
    if (a.X == b.X) {
        return a.Y < b.Y;
    } else {
        return a.X < b.X;
    }
}

int w[N], where[N], perm[N];
point p[N];

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

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y >> w[i];
        p[i] = point(x, y);
    }

    iota(perm, perm + n, 0);
    sort(perm, perm + n, [&](int i, int j) {
        return comp(p[i], p[j]);
    });

    segtree *maxi = new segtree();
    for (int i = 0; i < n; ++i) {
        maxi->update(i, w[perm[i]], 0, n - 1);
        where[perm[i]] = i;
    }

    vector<tuple<point, int, int>> vec;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i != j && comp(p[i], p[j])) {
                vec.push_back({p[j] - p[i], i, j});
            }
        }
    }

    sort(vec.begin(), vec.end(), [&](auto i, auto j) {
        if (cross(get<0>(i), get<0>(j)) == 0) {
            if (get<1>(i) == get<1>(j)) {
                return comp(p[get<2>(i)], p[get<2>(j)]);
            }
            return comp(p[get<1>(i)], p[get<1>(j)]);
        }
        return cross(get<0>(i), get<0>(j)) < 0;
    });

    long long ans = maxi->maxi;
    for (int i = 0, j = 0; i < (int) vec.size(); i = j) {
        while (j < (int) vec.size() && cross(get<0>(vec[i]), get<0>(vec[j])) == 0) {
            auto [v, a, b] = vec[j++];
            maxi->update(where[a], w[b], 0, n - 1);
            maxi->update(where[b], w[a], 0, n - 1);
            swap(where[a], where[b]);
        }
        ans = max(ans, maxi->maxi);
    }

    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 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 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 576 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 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 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 576 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
33 Correct 928 ms 49992 KB Output is correct
34 Correct 952 ms 50044 KB Output is correct
35 Correct 941 ms 50040 KB Output is correct
36 Correct 947 ms 49996 KB Output is correct
37 Correct 956 ms 50040 KB Output is correct
38 Correct 976 ms 50084 KB Output is correct
39 Correct 945 ms 50032 KB Output is correct
40 Correct 945 ms 50064 KB Output is correct
41 Correct 971 ms 50064 KB Output is correct
42 Correct 935 ms 50084 KB Output is correct
43 Correct 927 ms 50064 KB Output is correct
44 Correct 929 ms 50040 KB Output is correct
45 Correct 930 ms 50016 KB Output is correct
46 Correct 934 ms 50064 KB Output is correct
47 Correct 924 ms 50076 KB Output is correct
48 Correct 927 ms 50048 KB Output is correct
49 Correct 924 ms 49992 KB Output is correct
50 Correct 930 ms 50044 KB Output is correct
51 Correct 931 ms 49992 KB Output is correct
52 Correct 931 ms 50036 KB Output is correct
53 Correct 929 ms 50060 KB Output is correct
54 Correct 928 ms 50068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 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 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 576 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
33 Correct 928 ms 49992 KB Output is correct
34 Correct 952 ms 50044 KB Output is correct
35 Correct 941 ms 50040 KB Output is correct
36 Correct 947 ms 49996 KB Output is correct
37 Correct 956 ms 50040 KB Output is correct
38 Correct 976 ms 50084 KB Output is correct
39 Correct 945 ms 50032 KB Output is correct
40 Correct 945 ms 50064 KB Output is correct
41 Correct 971 ms 50064 KB Output is correct
42 Correct 935 ms 50084 KB Output is correct
43 Correct 927 ms 50064 KB Output is correct
44 Correct 929 ms 50040 KB Output is correct
45 Correct 930 ms 50016 KB Output is correct
46 Correct 934 ms 50064 KB Output is correct
47 Correct 924 ms 50076 KB Output is correct
48 Correct 927 ms 50048 KB Output is correct
49 Correct 924 ms 49992 KB Output is correct
50 Correct 930 ms 50044 KB Output is correct
51 Correct 931 ms 49992 KB Output is correct
52 Correct 931 ms 50036 KB Output is correct
53 Correct 929 ms 50060 KB Output is correct
54 Correct 928 ms 50068 KB Output is correct
55 Correct 940 ms 50124 KB Output is correct
56 Correct 933 ms 50068 KB Output is correct
57 Correct 940 ms 50064 KB Output is correct
58 Correct 949 ms 49948 KB Output is correct
59 Correct 937 ms 50064 KB Output is correct
60 Correct 946 ms 50096 KB Output is correct
61 Correct 969 ms 50044 KB Output is correct
62 Correct 939 ms 50008 KB Output is correct
63 Correct 940 ms 50068 KB Output is correct
64 Correct 954 ms 49992 KB Output is correct
65 Correct 935 ms 50064 KB Output is correct
66 Correct 938 ms 50072 KB Output is correct
67 Correct 932 ms 50064 KB Output is correct
68 Correct 934 ms 50064 KB Output is correct
69 Correct 945 ms 50064 KB Output is correct
70 Correct 935 ms 50064 KB Output is correct
71 Correct 938 ms 50036 KB Output is correct
72 Correct 950 ms 50040 KB Output is correct
73 Correct 949 ms 50040 KB Output is correct
74 Correct 950 ms 50000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 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 320 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 2 ms 588 KB Output is correct
37 Correct 2 ms 588 KB Output is correct
38 Correct 2 ms 576 KB Output is correct
39 Correct 2 ms 588 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 588 KB Output is correct
42 Correct 3 ms 588 KB Output is correct
43 Correct 2 ms 588 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 2 ms 588 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 2 ms 568 KB Output is correct
48 Correct 928 ms 49992 KB Output is correct
49 Correct 952 ms 50044 KB Output is correct
50 Correct 941 ms 50040 KB Output is correct
51 Correct 947 ms 49996 KB Output is correct
52 Correct 956 ms 50040 KB Output is correct
53 Correct 976 ms 50084 KB Output is correct
54 Correct 945 ms 50032 KB Output is correct
55 Correct 945 ms 50064 KB Output is correct
56 Correct 971 ms 50064 KB Output is correct
57 Correct 935 ms 50084 KB Output is correct
58 Correct 927 ms 50064 KB Output is correct
59 Correct 929 ms 50040 KB Output is correct
60 Correct 930 ms 50016 KB Output is correct
61 Correct 934 ms 50064 KB Output is correct
62 Correct 924 ms 50076 KB Output is correct
63 Correct 927 ms 50048 KB Output is correct
64 Correct 924 ms 49992 KB Output is correct
65 Correct 930 ms 50044 KB Output is correct
66 Correct 931 ms 49992 KB Output is correct
67 Correct 931 ms 50036 KB Output is correct
68 Correct 929 ms 50060 KB Output is correct
69 Correct 928 ms 50068 KB Output is correct
70 Correct 940 ms 50124 KB Output is correct
71 Correct 933 ms 50068 KB Output is correct
72 Correct 940 ms 50064 KB Output is correct
73 Correct 949 ms 49948 KB Output is correct
74 Correct 937 ms 50064 KB Output is correct
75 Correct 946 ms 50096 KB Output is correct
76 Correct 969 ms 50044 KB Output is correct
77 Correct 939 ms 50008 KB Output is correct
78 Correct 940 ms 50068 KB Output is correct
79 Correct 954 ms 49992 KB Output is correct
80 Correct 935 ms 50064 KB Output is correct
81 Correct 938 ms 50072 KB Output is correct
82 Correct 932 ms 50064 KB Output is correct
83 Correct 934 ms 50064 KB Output is correct
84 Correct 945 ms 50064 KB Output is correct
85 Correct 935 ms 50064 KB Output is correct
86 Correct 938 ms 50036 KB Output is correct
87 Correct 950 ms 50040 KB Output is correct
88 Correct 949 ms 50040 KB Output is correct
89 Correct 950 ms 50000 KB Output is correct
90 Correct 957 ms 49992 KB Output is correct
91 Correct 941 ms 50052 KB Output is correct
92 Correct 941 ms 50036 KB Output is correct
93 Correct 937 ms 50064 KB Output is correct
94 Correct 941 ms 49976 KB Output is correct
95 Correct 935 ms 50028 KB Output is correct
96 Correct 947 ms 50064 KB Output is correct
97 Correct 936 ms 50040 KB Output is correct
98 Correct 937 ms 50064 KB Output is correct
99 Correct 932 ms 50036 KB Output is correct
100 Correct 905 ms 50064 KB Output is correct
101 Correct 915 ms 50040 KB Output is correct
102 Correct 908 ms 50040 KB Output is correct
103 Correct 898 ms 50064 KB Output is correct
104 Correct 889 ms 50040 KB Output is correct
105 Correct 910 ms 50064 KB Output is correct
106 Correct 917 ms 50024 KB Output is correct
107 Correct 911 ms 50040 KB Output is correct
108 Correct 929 ms 50040 KB Output is correct
109 Correct 909 ms 50040 KB Output is correct
110 Correct 914 ms 50040 KB Output is correct
111 Correct 925 ms 50076 KB Output is correct
112 Correct 912 ms 50012 KB Output is correct
113 Correct 920 ms 49916 KB Output is correct
114 Correct 914 ms 50064 KB Output is correct
115 Correct 914 ms 49928 KB Output is correct
116 Correct 926 ms 49964 KB Output is correct
117 Correct 914 ms 50064 KB Output is correct
118 Correct 924 ms 50072 KB Output is correct
119 Correct 911 ms 50076 KB Output is correct
120 Correct 1 ms 204 KB Output is correct
121 Correct 1 ms 204 KB Output is correct
122 Correct 938 ms 50032 KB Output is correct
123 Correct 947 ms 50064 KB Output is correct
124 Correct 947 ms 50064 KB Output is correct
125 Correct 933 ms 50020 KB Output is correct
126 Correct 931 ms 50040 KB Output is correct
127 Correct 942 ms 50016 KB Output is correct
128 Correct 936 ms 50040 KB Output is correct
129 Correct 940 ms 50076 KB Output is correct
130 Correct 935 ms 50040 KB Output is correct
131 Correct 933 ms 50064 KB Output is correct
132 Correct 935 ms 50040 KB Output is correct
133 Correct 926 ms 50088 KB Output is correct