Submission #224600

# Submission time Handle Problem Language Result Execution time Memory
224600 2020-04-18T13:34:50 Z dolphingarlic Bulldozer (JOI17_bulldozer) C++14
100 / 100
1117 ms 50016 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

struct Node {
    ll l, r, tot, best;

    Node operator+(Node B) {
        return {max(l, tot + B.l), max(B.r, r + B.tot), tot + B.tot, max(max(best, B.best), r + B.l)};
    }
} segtree[8001];

struct Point {
    ll x, y, v;

    bool operator<(Point B) {
        if (x == B.x) return y < B.y;
        return x < B.x;
    }
} points[2001];

struct Line {
    ll dx, dy;
    int u, v;

    bool operator<(Line B) {
        if (dy * B.dx == B.dy * dx) return tie(u, v) < tie(B.u, B.v);
        return dy * B.dx < B.dy * dx;
    }
};
vector<Line> swaps;

int n, curr[2001];

void build(int node = 1, int l = 1, int r = n) {
    if (l == r) {
        ll v = max(points[l].v, 0ll);
        segtree[node] = {v, v, points[l].v, v};
    } else {
        int mid = (l + r) / 2;
        build(node * 2, l, mid);
        build(node * 2 + 1, mid + 1, r);
        segtree[node] = segtree[node * 2] + segtree[node * 2 + 1];
    }
}

void update(int pos, ll val, int node = 1, int l = 1, int r = n) {
    if (l == r) segtree[node] = {max(val, 0ll), max(val, 0ll), val, max(val, 0ll)};
    else {
        int mid = (l + r) / 2;
        if (pos > mid) update(pos, val, node * 2 + 1, mid + 1, r);
        else update(pos, val, node * 2, l, mid);
        segtree[node] = segtree[node * 2] + segtree[node * 2 + 1];
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    FOR(i, 1, n + 1) {
        cin >> points[i].x >> points[i].y >> points[i].v;
        curr[i] = i;
    }
    sort(points + 1, points + n + 1);
    FOR(i, 1, n + 1) FOR(j, i + 1, n + 1)
        swaps.push_back({points[j].x - points[i].x, points[j].y - points[i].y, i, j});
    sort(swaps.begin(), swaps.end());

    build();
    ll ans = segtree[1].best;
    FOR(i, 0, swaps.size()) {
        update(curr[swaps[i].u], points[swaps[i].v].v);
        update(curr[swaps[i].v], points[swaps[i].u].v);
        swap(curr[swaps[i].u], curr[swaps[i].v]);

        if (i == swaps.size() - 1) ans = max(ans, segtree[1].best);
        else if (swaps[i].dy * swaps[i + 1].dx != swaps[i + 1].dy * swaps[i].dx) ans = max(ans, segtree[1].best);
    }
    cout << ans;
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:2:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i, x, y) for (int i = x; i < y; i++)
bulldozer.cpp:73:9:
     FOR(i, 0, swaps.size()) {
         ~~~~~~~~~~~~~~~~~~              
bulldozer.cpp:73:5: note: in expansion of macro 'FOR'
     FOR(i, 0, swaps.size()) {
     ^~~
bulldozer.cpp:78:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == swaps.size() - 1) ans = max(ans, segtree[1].best);
             ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 6 ms 640 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 6 ms 640 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 1086 ms 49732 KB Output is correct
34 Correct 1081 ms 49836 KB Output is correct
35 Correct 1059 ms 49860 KB Output is correct
36 Correct 1060 ms 49708 KB Output is correct
37 Correct 1077 ms 49708 KB Output is correct
38 Correct 1040 ms 49708 KB Output is correct
39 Correct 1079 ms 49860 KB Output is correct
40 Correct 1060 ms 49820 KB Output is correct
41 Correct 1061 ms 49712 KB Output is correct
42 Correct 1062 ms 49836 KB Output is correct
43 Correct 1081 ms 49836 KB Output is correct
44 Correct 1086 ms 49868 KB Output is correct
45 Correct 1067 ms 49732 KB Output is correct
46 Correct 1082 ms 49716 KB Output is correct
47 Correct 1059 ms 49732 KB Output is correct
48 Correct 1051 ms 49860 KB Output is correct
49 Correct 1064 ms 49836 KB Output is correct
50 Correct 1055 ms 49812 KB Output is correct
51 Correct 1058 ms 49860 KB Output is correct
52 Correct 1081 ms 49836 KB Output is correct
53 Correct 1051 ms 49860 KB Output is correct
54 Correct 1047 ms 49712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 6 ms 640 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 6 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 1086 ms 49732 KB Output is correct
34 Correct 1081 ms 49836 KB Output is correct
35 Correct 1059 ms 49860 KB Output is correct
36 Correct 1060 ms 49708 KB Output is correct
37 Correct 1077 ms 49708 KB Output is correct
38 Correct 1040 ms 49708 KB Output is correct
39 Correct 1079 ms 49860 KB Output is correct
40 Correct 1060 ms 49820 KB Output is correct
41 Correct 1061 ms 49712 KB Output is correct
42 Correct 1062 ms 49836 KB Output is correct
43 Correct 1081 ms 49836 KB Output is correct
44 Correct 1086 ms 49868 KB Output is correct
45 Correct 1067 ms 49732 KB Output is correct
46 Correct 1082 ms 49716 KB Output is correct
47 Correct 1059 ms 49732 KB Output is correct
48 Correct 1051 ms 49860 KB Output is correct
49 Correct 1064 ms 49836 KB Output is correct
50 Correct 1055 ms 49812 KB Output is correct
51 Correct 1058 ms 49860 KB Output is correct
52 Correct 1081 ms 49836 KB Output is correct
53 Correct 1051 ms 49860 KB Output is correct
54 Correct 1047 ms 49712 KB Output is correct
55 Correct 1079 ms 49864 KB Output is correct
56 Correct 1091 ms 49860 KB Output is correct
57 Correct 1067 ms 49708 KB Output is correct
58 Correct 1068 ms 49836 KB Output is correct
59 Correct 1079 ms 49852 KB Output is correct
60 Correct 1100 ms 49732 KB Output is correct
61 Correct 1064 ms 49836 KB Output is correct
62 Correct 1105 ms 49836 KB Output is correct
63 Correct 1060 ms 49860 KB Output is correct
64 Correct 1058 ms 49736 KB Output is correct
65 Correct 1072 ms 49836 KB Output is correct
66 Correct 1067 ms 49732 KB Output is correct
67 Correct 1074 ms 49708 KB Output is correct
68 Correct 1087 ms 49860 KB Output is correct
69 Correct 1074 ms 49908 KB Output is correct
70 Correct 1094 ms 49880 KB Output is correct
71 Correct 1099 ms 49980 KB Output is correct
72 Correct 1098 ms 49872 KB Output is correct
73 Correct 1080 ms 49872 KB Output is correct
74 Correct 1112 ms 49860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 7 ms 704 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 7 ms 704 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 640 KB Output is correct
37 Correct 6 ms 640 KB Output is correct
38 Correct 6 ms 640 KB Output is correct
39 Correct 6 ms 640 KB Output is correct
40 Correct 6 ms 640 KB Output is correct
41 Correct 6 ms 640 KB Output is correct
42 Correct 6 ms 640 KB Output is correct
43 Correct 6 ms 640 KB Output is correct
44 Correct 6 ms 640 KB Output is correct
45 Correct 6 ms 640 KB Output is correct
46 Correct 6 ms 640 KB Output is correct
47 Correct 6 ms 640 KB Output is correct
48 Correct 1086 ms 49732 KB Output is correct
49 Correct 1081 ms 49836 KB Output is correct
50 Correct 1059 ms 49860 KB Output is correct
51 Correct 1060 ms 49708 KB Output is correct
52 Correct 1077 ms 49708 KB Output is correct
53 Correct 1040 ms 49708 KB Output is correct
54 Correct 1079 ms 49860 KB Output is correct
55 Correct 1060 ms 49820 KB Output is correct
56 Correct 1061 ms 49712 KB Output is correct
57 Correct 1062 ms 49836 KB Output is correct
58 Correct 1081 ms 49836 KB Output is correct
59 Correct 1086 ms 49868 KB Output is correct
60 Correct 1067 ms 49732 KB Output is correct
61 Correct 1082 ms 49716 KB Output is correct
62 Correct 1059 ms 49732 KB Output is correct
63 Correct 1051 ms 49860 KB Output is correct
64 Correct 1064 ms 49836 KB Output is correct
65 Correct 1055 ms 49812 KB Output is correct
66 Correct 1058 ms 49860 KB Output is correct
67 Correct 1081 ms 49836 KB Output is correct
68 Correct 1051 ms 49860 KB Output is correct
69 Correct 1047 ms 49712 KB Output is correct
70 Correct 1079 ms 49864 KB Output is correct
71 Correct 1091 ms 49860 KB Output is correct
72 Correct 1067 ms 49708 KB Output is correct
73 Correct 1068 ms 49836 KB Output is correct
74 Correct 1079 ms 49852 KB Output is correct
75 Correct 1100 ms 49732 KB Output is correct
76 Correct 1064 ms 49836 KB Output is correct
77 Correct 1105 ms 49836 KB Output is correct
78 Correct 1060 ms 49860 KB Output is correct
79 Correct 1058 ms 49736 KB Output is correct
80 Correct 1072 ms 49836 KB Output is correct
81 Correct 1067 ms 49732 KB Output is correct
82 Correct 1074 ms 49708 KB Output is correct
83 Correct 1087 ms 49860 KB Output is correct
84 Correct 1074 ms 49908 KB Output is correct
85 Correct 1094 ms 49880 KB Output is correct
86 Correct 1099 ms 49980 KB Output is correct
87 Correct 1098 ms 49872 KB Output is correct
88 Correct 1080 ms 49872 KB Output is correct
89 Correct 1112 ms 49860 KB Output is correct
90 Correct 1075 ms 49860 KB Output is correct
91 Correct 1117 ms 49860 KB Output is correct
92 Correct 1075 ms 49860 KB Output is correct
93 Correct 1087 ms 49860 KB Output is correct
94 Correct 1076 ms 49836 KB Output is correct
95 Correct 1069 ms 49732 KB Output is correct
96 Correct 1045 ms 49860 KB Output is correct
97 Correct 1066 ms 49872 KB Output is correct
98 Correct 1075 ms 49860 KB Output is correct
99 Correct 1074 ms 49736 KB Output is correct
100 Correct 889 ms 49712 KB Output is correct
101 Correct 873 ms 49748 KB Output is correct
102 Correct 873 ms 49836 KB Output is correct
103 Correct 865 ms 49740 KB Output is correct
104 Correct 877 ms 49836 KB Output is correct
105 Correct 941 ms 49736 KB Output is correct
106 Correct 923 ms 49860 KB Output is correct
107 Correct 913 ms 49860 KB Output is correct
108 Correct 940 ms 49836 KB Output is correct
109 Correct 928 ms 49836 KB Output is correct
110 Correct 965 ms 49736 KB Output is correct
111 Correct 971 ms 49732 KB Output is correct
112 Correct 966 ms 49860 KB Output is correct
113 Correct 966 ms 49748 KB Output is correct
114 Correct 974 ms 49840 KB Output is correct
115 Correct 970 ms 49860 KB Output is correct
116 Correct 989 ms 49836 KB Output is correct
117 Correct 967 ms 49836 KB Output is correct
118 Correct 967 ms 49732 KB Output is correct
119 Correct 979 ms 49860 KB Output is correct
120 Correct 4 ms 384 KB Output is correct
121 Correct 4 ms 384 KB Output is correct
122 Correct 1075 ms 49836 KB Output is correct
123 Correct 1067 ms 50016 KB Output is correct
124 Correct 1072 ms 49860 KB Output is correct
125 Correct 1075 ms 49860 KB Output is correct
126 Correct 1057 ms 49836 KB Output is correct
127 Correct 1057 ms 49856 KB Output is correct
128 Correct 1078 ms 49880 KB Output is correct
129 Correct 1057 ms 49836 KB Output is correct
130 Correct 1069 ms 49836 KB Output is correct
131 Correct 1082 ms 49836 KB Output is correct
132 Correct 1108 ms 49840 KB Output is correct
133 Correct 1067 ms 49836 KB Output is correct