Submission #219541

# Submission time Handle Problem Language Result Execution time Memory
219541 2020-04-05T13:51:58 Z balbit Bulldozer (JOI17_bulldozer) C++14
60 / 100
1184 ms 66640 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, int 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});
        }
    }

    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, 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 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 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 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 5 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 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 4 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 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 6 ms 768 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 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 4 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 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 6 ms 768 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
33 Correct 1116 ms 66488 KB Output is correct
34 Correct 1119 ms 66460 KB Output is correct
35 Correct 1102 ms 66460 KB Output is correct
36 Correct 1108 ms 66492 KB Output is correct
37 Correct 1098 ms 66460 KB Output is correct
38 Correct 1123 ms 66460 KB Output is correct
39 Correct 1093 ms 66460 KB Output is correct
40 Correct 1110 ms 66460 KB Output is correct
41 Correct 1109 ms 66464 KB Output is correct
42 Correct 1092 ms 66460 KB Output is correct
43 Correct 1110 ms 66460 KB Output is correct
44 Correct 1100 ms 66460 KB Output is correct
45 Correct 1103 ms 66460 KB Output is correct
46 Correct 1090 ms 66460 KB Output is correct
47 Correct 1105 ms 66640 KB Output is correct
48 Correct 1095 ms 66492 KB Output is correct
49 Correct 1090 ms 66464 KB Output is correct
50 Correct 1106 ms 66460 KB Output is correct
51 Correct 1113 ms 66492 KB Output is correct
52 Correct 1117 ms 66460 KB Output is correct
53 Correct 1096 ms 66460 KB Output is correct
54 Correct 1104 ms 66460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 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 4 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 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 6 ms 768 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
33 Correct 1116 ms 66488 KB Output is correct
34 Correct 1119 ms 66460 KB Output is correct
35 Correct 1102 ms 66460 KB Output is correct
36 Correct 1108 ms 66492 KB Output is correct
37 Correct 1098 ms 66460 KB Output is correct
38 Correct 1123 ms 66460 KB Output is correct
39 Correct 1093 ms 66460 KB Output is correct
40 Correct 1110 ms 66460 KB Output is correct
41 Correct 1109 ms 66464 KB Output is correct
42 Correct 1092 ms 66460 KB Output is correct
43 Correct 1110 ms 66460 KB Output is correct
44 Correct 1100 ms 66460 KB Output is correct
45 Correct 1103 ms 66460 KB Output is correct
46 Correct 1090 ms 66460 KB Output is correct
47 Correct 1105 ms 66640 KB Output is correct
48 Correct 1095 ms 66492 KB Output is correct
49 Correct 1090 ms 66464 KB Output is correct
50 Correct 1106 ms 66460 KB Output is correct
51 Correct 1113 ms 66492 KB Output is correct
52 Correct 1117 ms 66460 KB Output is correct
53 Correct 1096 ms 66460 KB Output is correct
54 Correct 1104 ms 66460 KB Output is correct
55 Correct 1129 ms 66460 KB Output is correct
56 Correct 1135 ms 66632 KB Output is correct
57 Correct 1126 ms 66332 KB Output is correct
58 Correct 1179 ms 66460 KB Output is correct
59 Correct 1117 ms 66460 KB Output is correct
60 Correct 1167 ms 66508 KB Output is correct
61 Correct 1123 ms 66460 KB Output is correct
62 Correct 1184 ms 66460 KB Output is correct
63 Correct 1138 ms 66460 KB Output is correct
64 Correct 1103 ms 66460 KB Output is correct
65 Incorrect 1126 ms 66460 KB Output isn't correct
66 Halted 0 ms 0 KB -
# 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 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 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 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 5 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 7 ms 768 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 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 4 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 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 7 ms 768 KB Output is correct
37 Correct 6 ms 768 KB Output is correct
38 Correct 6 ms 768 KB Output is correct
39 Correct 6 ms 768 KB Output is correct
40 Correct 6 ms 768 KB Output is correct
41 Correct 6 ms 768 KB Output is correct
42 Correct 6 ms 768 KB Output is correct
43 Correct 6 ms 768 KB Output is correct
44 Correct 6 ms 768 KB Output is correct
45 Correct 6 ms 768 KB Output is correct
46 Correct 6 ms 768 KB Output is correct
47 Correct 6 ms 768 KB Output is correct
48 Correct 1116 ms 66488 KB Output is correct
49 Correct 1119 ms 66460 KB Output is correct
50 Correct 1102 ms 66460 KB Output is correct
51 Correct 1108 ms 66492 KB Output is correct
52 Correct 1098 ms 66460 KB Output is correct
53 Correct 1123 ms 66460 KB Output is correct
54 Correct 1093 ms 66460 KB Output is correct
55 Correct 1110 ms 66460 KB Output is correct
56 Correct 1109 ms 66464 KB Output is correct
57 Correct 1092 ms 66460 KB Output is correct
58 Correct 1110 ms 66460 KB Output is correct
59 Correct 1100 ms 66460 KB Output is correct
60 Correct 1103 ms 66460 KB Output is correct
61 Correct 1090 ms 66460 KB Output is correct
62 Correct 1105 ms 66640 KB Output is correct
63 Correct 1095 ms 66492 KB Output is correct
64 Correct 1090 ms 66464 KB Output is correct
65 Correct 1106 ms 66460 KB Output is correct
66 Correct 1113 ms 66492 KB Output is correct
67 Correct 1117 ms 66460 KB Output is correct
68 Correct 1096 ms 66460 KB Output is correct
69 Correct 1104 ms 66460 KB Output is correct
70 Correct 1129 ms 66460 KB Output is correct
71 Correct 1135 ms 66632 KB Output is correct
72 Correct 1126 ms 66332 KB Output is correct
73 Correct 1179 ms 66460 KB Output is correct
74 Correct 1117 ms 66460 KB Output is correct
75 Correct 1167 ms 66508 KB Output is correct
76 Correct 1123 ms 66460 KB Output is correct
77 Correct 1184 ms 66460 KB Output is correct
78 Correct 1138 ms 66460 KB Output is correct
79 Correct 1103 ms 66460 KB Output is correct
80 Incorrect 1126 ms 66460 KB Output isn't correct
81 Halted 0 ms 0 KB -