Submission #219543

# Submission time Handle Problem Language Result Execution time Memory
219543 2020-04-05T13:58:06 Z balbit Bulldozer (JOI17_bulldozer) C++14
100 / 100
1036 ms 47912 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define SZ(x) (int)(x.size())
#define ALL(x) x.begin(),x.end()
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S &&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()

#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define bug(...)
#define endl '\n'
#endif // BALBIT

//#define assert(...)

const int maxn = 2005;

struct seg{
    ll sum, lv, rv, v;
    seg *lc=0, *rc=0;
};

int n;

void pull(seg *&o) {
    if (!o->lc) {
        if (o->v > 0)
            o->sum = o->lv = o->rv = o->v;
        else {
            o->sum = o->v;
            o->lv = o->rv = o->v = 0;
        }
    }else{
        assert(o->lc && o->rc);
        o->sum = o->lc->sum + o->rc->sum;
        o->lv = max(o->lc->lv, o->lc->sum + o->rc->lv);
        o->rv = max(o->rc->rv, o->rc->sum + o->lc->rv);
        o->v = max({o->lc->v, o->rc->v, o->lc->rv + o->rc->lv});
        assert(o->v >= 0);
    }
}

void MO(int p, ll v, seg *&o, int l=0, int r=n-1) {
    if (l > p || r<p) return;
    if (l == r) {
        o->v = v;
        pull(o);
        return;
    }
    int mid = l+r>>1;
    MO(p,v,o->lc,l,mid);
    MO(p,v,o->rc,mid+1,r);
    pull(o);
}

ll arr[maxn];
void build(seg * &o, int l=0, int r=n-1) {
    if (l == r) {
        o->v = arr[l]; pull(o); return;
    }
    int mid = l+r>>1;
    o->lc = new seg();
    build(o->lc, l, mid);
    o->rc = new seg();
    build(o->rc, mid+1, r);
    pull(o);
}

//#define double long double

struct pt{
    int x, y;
    ll v;
};

struct Ev{
    double sl;
    int a,b;
};

int at[maxn];

signed main(){
    IOS();
    cin>>n;
    seg* root = new seg();
    vector<pt> v(n);

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

    sort(v.begin(), v.end(), [&](pt a, pt b){return a.y!=b.y?a.y>b.y:a.x<b.x;});

    for (int i = 0; i<n; ++i) {
        arr[i] = v[i].v;
        bug(v[i].v);
        at[i] = i;
    }

    build(root);
    bug(root->v, root->sum);
    bug(root->lv, root->rv);

    ll re = root->v;

    vector<Ev> qu;

    for (int i = 0; i<n; ++i) for (int j = i+1; j<n; ++j) {
        if (v[i].y != v[j].y) {
            qu.pb({-(v[i].x-v[j].x)/(double)(v[i].y-v[j].y), i, j});
        }
    }

    stable_sort(ALL(qu), [&](Ev a, Ev b){return a.sl < b.sl;});

    for (int i = 0; i<SZ(qu); ++i) {
        Ev & e = qu[i];
        bug("swapping", e.a, e.b);
//        assert(abs(at[e.a]-at[e.b]) == 1);
        MO(at[e.a], v[e.b].v, root);
        MO(at[e.b], v[e.a].v, root);
        swap(at[e.a], at[e.b]);
        if (i==SZ(qu)-1 || qu[i+1].sl != qu[i].sl) re = max(re, root->v);
    }

    cout<<re<<endl;

}

Compilation message

bulldozer.cpp: In function 'void MO(int, long long int, seg*&, int, int)':
bulldozer.cpp:57:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l+r>>1;
               ~^~
bulldozer.cpp: In function 'void build(seg*&, int, int)':
bulldozer.cpp:68:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l+r>>1;
               ~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 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 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 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 5 ms 384 KB Output is correct
17 Correct 4 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 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 7 ms 512 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 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 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 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 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 5 ms 384 KB Output is correct
17 Correct 4 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 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 7 ms 512 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 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 971 ms 47772 KB Output is correct
34 Correct 975 ms 47772 KB Output is correct
35 Correct 981 ms 47772 KB Output is correct
36 Correct 984 ms 47804 KB Output is correct
37 Correct 994 ms 47772 KB Output is correct
38 Correct 981 ms 47772 KB Output is correct
39 Correct 982 ms 47776 KB Output is correct
40 Correct 986 ms 47772 KB Output is correct
41 Correct 994 ms 47772 KB Output is correct
42 Correct 992 ms 47776 KB Output is correct
43 Correct 969 ms 47768 KB Output is correct
44 Correct 973 ms 47772 KB Output is correct
45 Correct 977 ms 47772 KB Output is correct
46 Correct 967 ms 47776 KB Output is correct
47 Correct 967 ms 47808 KB Output is correct
48 Correct 998 ms 47772 KB Output is correct
49 Correct 969 ms 47772 KB Output is correct
50 Correct 1016 ms 47768 KB Output is correct
51 Correct 1036 ms 47772 KB Output is correct
52 Correct 1018 ms 47804 KB Output is correct
53 Correct 973 ms 47772 KB Output is correct
54 Correct 970 ms 47772 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 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 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 5 ms 384 KB Output is correct
17 Correct 4 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 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 7 ms 512 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 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 971 ms 47772 KB Output is correct
34 Correct 975 ms 47772 KB Output is correct
35 Correct 981 ms 47772 KB Output is correct
36 Correct 984 ms 47804 KB Output is correct
37 Correct 994 ms 47772 KB Output is correct
38 Correct 981 ms 47772 KB Output is correct
39 Correct 982 ms 47776 KB Output is correct
40 Correct 986 ms 47772 KB Output is correct
41 Correct 994 ms 47772 KB Output is correct
42 Correct 992 ms 47776 KB Output is correct
43 Correct 969 ms 47768 KB Output is correct
44 Correct 973 ms 47772 KB Output is correct
45 Correct 977 ms 47772 KB Output is correct
46 Correct 967 ms 47776 KB Output is correct
47 Correct 967 ms 47808 KB Output is correct
48 Correct 998 ms 47772 KB Output is correct
49 Correct 969 ms 47772 KB Output is correct
50 Correct 1016 ms 47768 KB Output is correct
51 Correct 1036 ms 47772 KB Output is correct
52 Correct 1018 ms 47804 KB Output is correct
53 Correct 973 ms 47772 KB Output is correct
54 Correct 970 ms 47772 KB Output is correct
55 Correct 975 ms 47772 KB Output is correct
56 Correct 1016 ms 47780 KB Output is correct
57 Correct 984 ms 47772 KB Output is correct
58 Correct 996 ms 47772 KB Output is correct
59 Correct 978 ms 47652 KB Output is correct
60 Correct 986 ms 47772 KB Output is correct
61 Correct 1000 ms 47768 KB Output is correct
62 Correct 976 ms 47772 KB Output is correct
63 Correct 987 ms 47772 KB Output is correct
64 Correct 977 ms 47772 KB Output is correct
65 Correct 990 ms 47772 KB Output is correct
66 Correct 983 ms 47644 KB Output is correct
67 Correct 989 ms 47644 KB Output is correct
68 Correct 987 ms 47644 KB Output is correct
69 Correct 990 ms 47872 KB Output is correct
70 Correct 992 ms 47644 KB Output is correct
71 Correct 976 ms 47644 KB Output is correct
72 Correct 979 ms 47644 KB Output is correct
73 Correct 986 ms 47648 KB Output is correct
74 Correct 976 ms 47644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 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 6 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 640 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 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 512 KB Output is correct
37 Correct 6 ms 512 KB Output is correct
38 Correct 6 ms 512 KB Output is correct
39 Correct 7 ms 512 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 512 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 6 ms 512 KB Output is correct
45 Correct 6 ms 512 KB Output is correct
46 Correct 6 ms 512 KB Output is correct
47 Correct 6 ms 640 KB Output is correct
48 Correct 971 ms 47772 KB Output is correct
49 Correct 975 ms 47772 KB Output is correct
50 Correct 981 ms 47772 KB Output is correct
51 Correct 984 ms 47804 KB Output is correct
52 Correct 994 ms 47772 KB Output is correct
53 Correct 981 ms 47772 KB Output is correct
54 Correct 982 ms 47776 KB Output is correct
55 Correct 986 ms 47772 KB Output is correct
56 Correct 994 ms 47772 KB Output is correct
57 Correct 992 ms 47776 KB Output is correct
58 Correct 969 ms 47768 KB Output is correct
59 Correct 973 ms 47772 KB Output is correct
60 Correct 977 ms 47772 KB Output is correct
61 Correct 967 ms 47776 KB Output is correct
62 Correct 967 ms 47808 KB Output is correct
63 Correct 998 ms 47772 KB Output is correct
64 Correct 969 ms 47772 KB Output is correct
65 Correct 1016 ms 47768 KB Output is correct
66 Correct 1036 ms 47772 KB Output is correct
67 Correct 1018 ms 47804 KB Output is correct
68 Correct 973 ms 47772 KB Output is correct
69 Correct 970 ms 47772 KB Output is correct
70 Correct 975 ms 47772 KB Output is correct
71 Correct 1016 ms 47780 KB Output is correct
72 Correct 984 ms 47772 KB Output is correct
73 Correct 996 ms 47772 KB Output is correct
74 Correct 978 ms 47652 KB Output is correct
75 Correct 986 ms 47772 KB Output is correct
76 Correct 1000 ms 47768 KB Output is correct
77 Correct 976 ms 47772 KB Output is correct
78 Correct 987 ms 47772 KB Output is correct
79 Correct 977 ms 47772 KB Output is correct
80 Correct 990 ms 47772 KB Output is correct
81 Correct 983 ms 47644 KB Output is correct
82 Correct 989 ms 47644 KB Output is correct
83 Correct 987 ms 47644 KB Output is correct
84 Correct 990 ms 47872 KB Output is correct
85 Correct 992 ms 47644 KB Output is correct
86 Correct 976 ms 47644 KB Output is correct
87 Correct 979 ms 47644 KB Output is correct
88 Correct 986 ms 47648 KB Output is correct
89 Correct 976 ms 47644 KB Output is correct
90 Correct 978 ms 47776 KB Output is correct
91 Correct 977 ms 47912 KB Output is correct
92 Correct 992 ms 47772 KB Output is correct
93 Correct 973 ms 47772 KB Output is correct
94 Correct 987 ms 47772 KB Output is correct
95 Correct 987 ms 47772 KB Output is correct
96 Correct 984 ms 47652 KB Output is correct
97 Correct 977 ms 47776 KB Output is correct
98 Correct 993 ms 47776 KB Output is correct
99 Correct 987 ms 47772 KB Output is correct
100 Correct 818 ms 47772 KB Output is correct
101 Correct 820 ms 47900 KB Output is correct
102 Correct 809 ms 47772 KB Output is correct
103 Correct 814 ms 47804 KB Output is correct
104 Correct 816 ms 47768 KB Output is correct
105 Correct 861 ms 47772 KB Output is correct
106 Correct 869 ms 47772 KB Output is correct
107 Correct 855 ms 47824 KB Output is correct
108 Correct 868 ms 47804 KB Output is correct
109 Correct 864 ms 47772 KB Output is correct
110 Correct 782 ms 47036 KB Output is correct
111 Correct 794 ms 47004 KB Output is correct
112 Correct 774 ms 47004 KB Output is correct
113 Correct 780 ms 47036 KB Output is correct
114 Correct 778 ms 47004 KB Output is correct
115 Correct 783 ms 47004 KB Output is correct
116 Correct 785 ms 47036 KB Output is correct
117 Correct 786 ms 47000 KB Output is correct
118 Correct 788 ms 47008 KB Output is correct
119 Correct 791 ms 47036 KB Output is correct
120 Correct 5 ms 384 KB Output is correct
121 Correct 5 ms 384 KB Output is correct
122 Correct 970 ms 47772 KB Output is correct
123 Correct 970 ms 47644 KB Output is correct
124 Correct 998 ms 47772 KB Output is correct
125 Correct 978 ms 47772 KB Output is correct
126 Correct 980 ms 47772 KB Output is correct
127 Correct 971 ms 47772 KB Output is correct
128 Correct 986 ms 47772 KB Output is correct
129 Correct 978 ms 47772 KB Output is correct
130 Correct 981 ms 47772 KB Output is correct
131 Correct 974 ms 47816 KB Output is correct
132 Correct 975 ms 47772 KB Output is correct
133 Correct 990 ms 47772 KB Output is correct