Submission #59023

# Submission time Handle Problem Language Result Execution time Memory
59023 2018-07-20T08:32:19 Z gusfring Bulldozer (JOI17_bulldozer) C++14
100 / 100
1382 ms 33488 KB
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
ll cross(pii a, pii b) {
    return 1LL * a.first * b.second - 1LL * a.second * b.first;
}
 
int N;
struct Point {
    int x, y, w;
    bool operator <(const Point &i) const {
        return y < i.y || (y == i.y && x < i.x);
    }
};
Point P[2010];
int pnt[2010];
vector<pair<pii, pii> > line;
ll ans;
 
bool cmp(pair<pii, pii> a, pair<pii, pii> b) {
    if(cross(a.first, b.first) != 0) return cross(a.first, b.first) > 0;
    return a.second < b.second;
}
 
struct node {
    int len;
    ll sum, mx, lmx, rmx;
};
 
node mrg(node &a, node &b) {
    node ret;
    ret.len = a.len + b.len;
    ret.sum = a.sum + b.sum;
    ret.lmx = max(a.lmx, a.sum + b.lmx);
    ret.rmx = max(b.rmx, b.sum + a.rmx);
    ret.mx = max(a.mx, b.mx);
    ret.mx = max(ret.mx, a.rmx + b.lmx);
    return ret;
}
 
struct BIT {
    vector<node> tree;
    void init() {
        tree = vector<node>(4 * N);
        build(0, N - 1, 1);
    }
    void build(int l, int r, int n) {
        if(l == r) {
            tree[n] = { 1, P[l].w, P[l].w, P[l].w, P[l].w };
            return;
        }
        int m = (l + r)>>1;
        build(l, m, 2*n);
        build(m + 1, r, 2*n + 1);
        tree[n] = mrg(tree[2*n], tree[2*n + 1]);
    }
    void upd(int idx, node val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] = val;
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = mrg(tree[2*n], tree[2*n + 1]);
    }
} bit;
 
int main() {
    scanf("%d", &N);
 
    for(int i = 0; i < N; i++) {
        scanf("%d %d %d", &P[i].x, &P[i].y, &P[i].w);
    }
 
    sort(P, P + N);
 
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            line.push_back({ { P[j].x - P[i].x, P[j].y - P[i].y }, {i, j} });
        }
    }
    for(int i = 0; i < N; i++) pnt[i] = i;
 
    sort(line.begin(), line.end(), cmp);
 
    bit.init();
    ans = max(ans, bit.tree[1].mx);
 
    int s = 0;
    for(int i = 0; i < line.size(); i++) {
        if(i == (int)line.size() - 1 || cross(line[i].first, line[i + 1].first) != 0) {
            for(int j = s; j <= i; j++) {
                int a = line[j].second.first;
                int b = line[j].second.second;
                swap(P[ pnt[a] ], P[ pnt[b] ]);
                swap(pnt[a], pnt[b]);
 
                bit.upd(pnt[a], { 1, P[ pnt[a] ].w, P[ pnt[a] ].w, P[ pnt[a] ].w, P[ pnt[a] ].w }, 0, N - 1, 1);
                bit.upd(pnt[b], { 1, P[ pnt[b] ].w, P[ pnt[b] ].w, P[ pnt[b] ].w, P[ pnt[b] ].w }, 0, N - 1, 1);
            }
 
            ans = max(ans, bit.tree[1].mx);
            s = i + 1;
        }
    }
 
    printf("%lld", ans);
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:95:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < line.size(); i++) {
                    ~~^~~~~~~~~~~~~
bulldozer.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
bulldozer.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &P[i].x, &P[i].y, &P[i].w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 484 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 4 ms 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 484 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 4 ms 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 1334 ms 33328 KB Output is correct
34 Correct 1257 ms 33356 KB Output is correct
35 Correct 1297 ms 33340 KB Output is correct
36 Correct 1343 ms 33356 KB Output is correct
37 Correct 1363 ms 33352 KB Output is correct
38 Correct 1250 ms 33340 KB Output is correct
39 Correct 1259 ms 33356 KB Output is correct
40 Correct 1259 ms 33340 KB Output is correct
41 Correct 1282 ms 33360 KB Output is correct
42 Correct 1326 ms 33356 KB Output is correct
43 Correct 1293 ms 33356 KB Output is correct
44 Correct 1247 ms 33340 KB Output is correct
45 Correct 1240 ms 33340 KB Output is correct
46 Correct 1258 ms 33340 KB Output is correct
47 Correct 1259 ms 33356 KB Output is correct
48 Correct 1262 ms 33356 KB Output is correct
49 Correct 1274 ms 33328 KB Output is correct
50 Correct 1256 ms 33340 KB Output is correct
51 Correct 1263 ms 33340 KB Output is correct
52 Correct 1264 ms 33340 KB Output is correct
53 Correct 1255 ms 33344 KB Output is correct
54 Correct 1269 ms 33356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 484 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 4 ms 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 1334 ms 33328 KB Output is correct
34 Correct 1257 ms 33356 KB Output is correct
35 Correct 1297 ms 33340 KB Output is correct
36 Correct 1343 ms 33356 KB Output is correct
37 Correct 1363 ms 33352 KB Output is correct
38 Correct 1250 ms 33340 KB Output is correct
39 Correct 1259 ms 33356 KB Output is correct
40 Correct 1259 ms 33340 KB Output is correct
41 Correct 1282 ms 33360 KB Output is correct
42 Correct 1326 ms 33356 KB Output is correct
43 Correct 1293 ms 33356 KB Output is correct
44 Correct 1247 ms 33340 KB Output is correct
45 Correct 1240 ms 33340 KB Output is correct
46 Correct 1258 ms 33340 KB Output is correct
47 Correct 1259 ms 33356 KB Output is correct
48 Correct 1262 ms 33356 KB Output is correct
49 Correct 1274 ms 33328 KB Output is correct
50 Correct 1256 ms 33340 KB Output is correct
51 Correct 1263 ms 33340 KB Output is correct
52 Correct 1264 ms 33340 KB Output is correct
53 Correct 1255 ms 33344 KB Output is correct
54 Correct 1269 ms 33356 KB Output is correct
55 Correct 1290 ms 33328 KB Output is correct
56 Correct 1334 ms 33328 KB Output is correct
57 Correct 1264 ms 33340 KB Output is correct
58 Correct 1257 ms 33356 KB Output is correct
59 Correct 1257 ms 33340 KB Output is correct
60 Correct 1299 ms 33356 KB Output is correct
61 Correct 1337 ms 33340 KB Output is correct
62 Correct 1262 ms 33288 KB Output is correct
63 Correct 1250 ms 33356 KB Output is correct
64 Correct 1279 ms 33256 KB Output is correct
65 Correct 1317 ms 33356 KB Output is correct
66 Correct 1270 ms 33336 KB Output is correct
67 Correct 1266 ms 33356 KB Output is correct
68 Correct 1298 ms 33244 KB Output is correct
69 Correct 1257 ms 33484 KB Output is correct
70 Correct 1257 ms 33340 KB Output is correct
71 Correct 1302 ms 33364 KB Output is correct
72 Correct 1326 ms 33324 KB Output is correct
73 Correct 1305 ms 33340 KB Output is correct
74 Correct 1295 ms 33300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 4 ms 512 KB Output is correct
40 Correct 4 ms 512 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 4 ms 512 KB Output is correct
44 Correct 4 ms 484 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 1334 ms 33328 KB Output is correct
49 Correct 1257 ms 33356 KB Output is correct
50 Correct 1297 ms 33340 KB Output is correct
51 Correct 1343 ms 33356 KB Output is correct
52 Correct 1363 ms 33352 KB Output is correct
53 Correct 1250 ms 33340 KB Output is correct
54 Correct 1259 ms 33356 KB Output is correct
55 Correct 1259 ms 33340 KB Output is correct
56 Correct 1282 ms 33360 KB Output is correct
57 Correct 1326 ms 33356 KB Output is correct
58 Correct 1293 ms 33356 KB Output is correct
59 Correct 1247 ms 33340 KB Output is correct
60 Correct 1240 ms 33340 KB Output is correct
61 Correct 1258 ms 33340 KB Output is correct
62 Correct 1259 ms 33356 KB Output is correct
63 Correct 1262 ms 33356 KB Output is correct
64 Correct 1274 ms 33328 KB Output is correct
65 Correct 1256 ms 33340 KB Output is correct
66 Correct 1263 ms 33340 KB Output is correct
67 Correct 1264 ms 33340 KB Output is correct
68 Correct 1255 ms 33344 KB Output is correct
69 Correct 1269 ms 33356 KB Output is correct
70 Correct 1290 ms 33328 KB Output is correct
71 Correct 1334 ms 33328 KB Output is correct
72 Correct 1264 ms 33340 KB Output is correct
73 Correct 1257 ms 33356 KB Output is correct
74 Correct 1257 ms 33340 KB Output is correct
75 Correct 1299 ms 33356 KB Output is correct
76 Correct 1337 ms 33340 KB Output is correct
77 Correct 1262 ms 33288 KB Output is correct
78 Correct 1250 ms 33356 KB Output is correct
79 Correct 1279 ms 33256 KB Output is correct
80 Correct 1317 ms 33356 KB Output is correct
81 Correct 1270 ms 33336 KB Output is correct
82 Correct 1266 ms 33356 KB Output is correct
83 Correct 1298 ms 33244 KB Output is correct
84 Correct 1257 ms 33484 KB Output is correct
85 Correct 1257 ms 33340 KB Output is correct
86 Correct 1302 ms 33364 KB Output is correct
87 Correct 1326 ms 33324 KB Output is correct
88 Correct 1305 ms 33340 KB Output is correct
89 Correct 1295 ms 33300 KB Output is correct
90 Correct 1295 ms 33488 KB Output is correct
91 Correct 1280 ms 33340 KB Output is correct
92 Correct 1279 ms 33328 KB Output is correct
93 Correct 1253 ms 33364 KB Output is correct
94 Correct 1256 ms 33328 KB Output is correct
95 Correct 1271 ms 33380 KB Output is correct
96 Correct 1284 ms 33356 KB Output is correct
97 Correct 1280 ms 33320 KB Output is correct
98 Correct 1317 ms 33356 KB Output is correct
99 Correct 1258 ms 33324 KB Output is correct
100 Correct 1201 ms 33332 KB Output is correct
101 Correct 1216 ms 33312 KB Output is correct
102 Correct 1210 ms 33260 KB Output is correct
103 Correct 1237 ms 33336 KB Output is correct
104 Correct 1243 ms 33364 KB Output is correct
105 Correct 1253 ms 33340 KB Output is correct
106 Correct 1252 ms 33340 KB Output is correct
107 Correct 1254 ms 33360 KB Output is correct
108 Correct 1284 ms 33340 KB Output is correct
109 Correct 1295 ms 33344 KB Output is correct
110 Correct 1240 ms 33356 KB Output is correct
111 Correct 1286 ms 33344 KB Output is correct
112 Correct 1280 ms 33356 KB Output is correct
113 Correct 1269 ms 33340 KB Output is correct
114 Correct 1269 ms 33340 KB Output is correct
115 Correct 1252 ms 33356 KB Output is correct
116 Correct 1246 ms 33332 KB Output is correct
117 Correct 1240 ms 33484 KB Output is correct
118 Correct 1230 ms 33348 KB Output is correct
119 Correct 1246 ms 33340 KB Output is correct
120 Correct 2 ms 256 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 1252 ms 33376 KB Output is correct
123 Correct 1271 ms 33340 KB Output is correct
124 Correct 1279 ms 33360 KB Output is correct
125 Correct 1262 ms 33356 KB Output is correct
126 Correct 1232 ms 33340 KB Output is correct
127 Correct 1283 ms 33356 KB Output is correct
128 Correct 1267 ms 33356 KB Output is correct
129 Correct 1273 ms 33352 KB Output is correct
130 Correct 1278 ms 33360 KB Output is correct
131 Correct 1290 ms 33356 KB Output is correct
132 Correct 1382 ms 33340 KB Output is correct
133 Correct 1341 ms 33340 KB Output is correct