Submission #110006

# Submission time Handle Problem Language Result Execution time Memory
110006 2019-05-08T17:23:29 Z popovicirobert Bulldozer (JOI17_bulldozer) C++14
75 / 100
2000 ms 33492 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const ll INF = 1e18;

struct SegTree {

    struct Node {
        ll pref, suff;
        ll best, sum;
    };

    vector <Node> aint;
    int n;

    inline void init(int _n) {
        n = _n;
        aint.resize(4 * n + 1, {-INF, -INF, -INF, -INF});
    }

    inline void refresh(int nod) {
        aint[nod].sum = aint[2 * nod].sum + aint[2 * nod + 1].sum;
        aint[nod].pref = max(aint[2 * nod].pref, aint[2 * nod].sum + aint[2 * nod + 1].pref);
        aint[nod].suff = max(aint[2 * nod + 1].suff, aint[2 * nod + 1].sum + aint[2 * nod].suff);
        aint[nod].best = max(max(aint[2 * nod].best, aint[2 * nod + 1].best), aint[2 * nod].suff + aint[2 * nod + 1].pref);
    }

    void update(int nod, int left, int right, int pos, int val) {
        if(left == right) {
            aint[nod] = {val, val, val, val};
        }
        else {
            int mid = (left + right) / 2;
            if(pos <= mid) update(2 * nod, left, mid, pos, val);
            else update(2 * nod + 1, mid + 1, right, pos, val);
            refresh(nod);
        }
    }

};

struct Point {
    int x, y;
    int val;
    bool operator <(const Point &other) const {
        if(x == other.x)
            return y < other.y;
        return x < other.x;
    }
};

struct Slope {
    double s;
    int a, b;
    bool operator <(const Slope &other) const {
        return other.s - s > 0.0;
    }
};

inline double get(Point &a, Point &b) {
    if(a.x == b.x)
        return 1.0 * INF;
    return 1.0 * (b.y - a.y) / (b.x - a.x);
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    vector <Point> pts(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> pts[i].x >> pts[i].y >> pts[i].val;
    }

    sort(next(pts.begin()), pts.end());

    vector <Slope> slp;
    for(i = 1; i <= n; i++) {
        for(j = i + 1; j <= n; j++) {
            slp.push_back({get(pts[i], pts[j]), i, j});
        }
    }

    sort(slp.begin(), slp.end());

    SegTree st; st.init(n);
    vector <int> pos(n + 1);

    for(i = 1; i <= n; i++) {
        st.update(1, 1, n, i, pts[i].val);
        pos[i] = i;
    }

    ll ans = max(0LL, st.aint[1].best);

    for(auto it : slp) {
        int a = it.a, b = it.b;

        if(abs(pos[a] - pos[b]) > 1) {
            while(1) {

            }
        }

        st.update(1, 1, n, pos[a], pts[b].val);
        st.update(1, 1, n, pos[b], pts[a].val);
        swap(pos[a], pos[b]);

        ans = max(ans, st.aint[1].best);

    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Execution timed out 2056 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 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 384 KB Output is correct
14 Correct 2 ms 384 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 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 556 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 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 384 KB Output is correct
14 Correct 2 ms 384 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 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 556 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 686 ms 33344 KB Output is correct
34 Correct 686 ms 33424 KB Output is correct
35 Correct 689 ms 33492 KB Output is correct
36 Correct 675 ms 33316 KB Output is correct
37 Correct 685 ms 33388 KB Output is correct
38 Correct 679 ms 33344 KB Output is correct
39 Correct 692 ms 33420 KB Output is correct
40 Correct 684 ms 33280 KB Output is correct
41 Correct 702 ms 33332 KB Output is correct
42 Correct 674 ms 33356 KB Output is correct
43 Correct 678 ms 33372 KB Output is correct
44 Correct 675 ms 33488 KB Output is correct
45 Correct 673 ms 33344 KB Output is correct
46 Correct 682 ms 33360 KB Output is correct
47 Correct 701 ms 33344 KB Output is correct
48 Correct 710 ms 33344 KB Output is correct
49 Correct 743 ms 33328 KB Output is correct
50 Correct 706 ms 33344 KB Output is correct
51 Correct 692 ms 33364 KB Output is correct
52 Correct 699 ms 33344 KB Output is correct
53 Correct 672 ms 33360 KB Output is correct
54 Correct 683 ms 33360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 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 384 KB Output is correct
14 Correct 2 ms 384 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 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 556 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 686 ms 33344 KB Output is correct
34 Correct 686 ms 33424 KB Output is correct
35 Correct 689 ms 33492 KB Output is correct
36 Correct 675 ms 33316 KB Output is correct
37 Correct 685 ms 33388 KB Output is correct
38 Correct 679 ms 33344 KB Output is correct
39 Correct 692 ms 33420 KB Output is correct
40 Correct 684 ms 33280 KB Output is correct
41 Correct 702 ms 33332 KB Output is correct
42 Correct 674 ms 33356 KB Output is correct
43 Correct 678 ms 33372 KB Output is correct
44 Correct 675 ms 33488 KB Output is correct
45 Correct 673 ms 33344 KB Output is correct
46 Correct 682 ms 33360 KB Output is correct
47 Correct 701 ms 33344 KB Output is correct
48 Correct 710 ms 33344 KB Output is correct
49 Correct 743 ms 33328 KB Output is correct
50 Correct 706 ms 33344 KB Output is correct
51 Correct 692 ms 33364 KB Output is correct
52 Correct 699 ms 33344 KB Output is correct
53 Correct 672 ms 33360 KB Output is correct
54 Correct 683 ms 33360 KB Output is correct
55 Correct 692 ms 33356 KB Output is correct
56 Correct 706 ms 33360 KB Output is correct
57 Correct 708 ms 33360 KB Output is correct
58 Correct 715 ms 33356 KB Output is correct
59 Correct 699 ms 33472 KB Output is correct
60 Correct 713 ms 33344 KB Output is correct
61 Correct 711 ms 33344 KB Output is correct
62 Correct 678 ms 33360 KB Output is correct
63 Correct 683 ms 33360 KB Output is correct
64 Correct 678 ms 33364 KB Output is correct
65 Correct 677 ms 33352 KB Output is correct
66 Correct 680 ms 33344 KB Output is correct
67 Correct 673 ms 33364 KB Output is correct
68 Correct 677 ms 33344 KB Output is correct
69 Correct 677 ms 33344 KB Output is correct
70 Correct 688 ms 33360 KB Output is correct
71 Correct 678 ms 33344 KB Output is correct
72 Correct 680 ms 33348 KB Output is correct
73 Correct 686 ms 33360 KB Output is correct
74 Correct 682 ms 33360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2056 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -