답안 #219536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219536 2020-04-05T13:44:42 Z balbit Bulldozer (JOI17_bulldozer) C++14
80 / 100
1199 ms 66716 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:21:0: warning: "assert" redefined
 #define assert(...)
 
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from bulldozer.cpp:1:
/usr/include/assert.h:88:0: note: this is the location of the previous definition
 # define assert(expr)       \
 
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;
               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 5 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 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 7 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 5 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 512 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 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 6 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 7 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 7 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
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 7 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 5 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 512 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 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 6 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 7 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 7 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 1109 ms 66588 KB Output is correct
34 Correct 1102 ms 66460 KB Output is correct
35 Correct 1104 ms 66460 KB Output is correct
36 Correct 1108 ms 66464 KB Output is correct
37 Correct 1113 ms 66592 KB Output is correct
38 Correct 1130 ms 66492 KB Output is correct
39 Correct 1111 ms 66460 KB Output is correct
40 Correct 1118 ms 66460 KB Output is correct
41 Correct 1112 ms 66564 KB Output is correct
42 Correct 1107 ms 66588 KB Output is correct
43 Correct 1151 ms 66460 KB Output is correct
44 Correct 1150 ms 66460 KB Output is correct
45 Correct 1107 ms 66716 KB Output is correct
46 Correct 1083 ms 66496 KB Output is correct
47 Correct 1091 ms 66460 KB Output is correct
48 Correct 1127 ms 66460 KB Output is correct
49 Correct 1124 ms 66460 KB Output is correct
50 Correct 1129 ms 66492 KB Output is correct
51 Correct 1102 ms 66568 KB Output is correct
52 Correct 1098 ms 66588 KB Output is correct
53 Correct 1088 ms 66492 KB Output is correct
54 Correct 1098 ms 66492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 7 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 5 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 512 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 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 6 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 7 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 7 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 1109 ms 66588 KB Output is correct
34 Correct 1102 ms 66460 KB Output is correct
35 Correct 1104 ms 66460 KB Output is correct
36 Correct 1108 ms 66464 KB Output is correct
37 Correct 1113 ms 66592 KB Output is correct
38 Correct 1130 ms 66492 KB Output is correct
39 Correct 1111 ms 66460 KB Output is correct
40 Correct 1118 ms 66460 KB Output is correct
41 Correct 1112 ms 66564 KB Output is correct
42 Correct 1107 ms 66588 KB Output is correct
43 Correct 1151 ms 66460 KB Output is correct
44 Correct 1150 ms 66460 KB Output is correct
45 Correct 1107 ms 66716 KB Output is correct
46 Correct 1083 ms 66496 KB Output is correct
47 Correct 1091 ms 66460 KB Output is correct
48 Correct 1127 ms 66460 KB Output is correct
49 Correct 1124 ms 66460 KB Output is correct
50 Correct 1129 ms 66492 KB Output is correct
51 Correct 1102 ms 66568 KB Output is correct
52 Correct 1098 ms 66588 KB Output is correct
53 Correct 1088 ms 66492 KB Output is correct
54 Correct 1098 ms 66492 KB Output is correct
55 Correct 1101 ms 66460 KB Output is correct
56 Correct 1110 ms 66456 KB Output is correct
57 Correct 1147 ms 66460 KB Output is correct
58 Correct 1199 ms 66460 KB Output is correct
59 Correct 1143 ms 66620 KB Output is correct
60 Correct 1124 ms 66592 KB Output is correct
61 Correct 1112 ms 66588 KB Output is correct
62 Correct 1175 ms 66592 KB Output is correct
63 Correct 1161 ms 66588 KB Output is correct
64 Correct 1142 ms 66460 KB Output is correct
65 Correct 1149 ms 66460 KB Output is correct
66 Correct 1137 ms 66588 KB Output is correct
67 Correct 1118 ms 66492 KB Output is correct
68 Correct 1107 ms 66456 KB Output is correct
69 Correct 1103 ms 66460 KB Output is correct
70 Correct 1104 ms 66460 KB Output is correct
71 Correct 1106 ms 66636 KB Output is correct
72 Correct 1128 ms 66460 KB Output is correct
73 Correct 1121 ms 66456 KB Output is correct
74 Correct 1134 ms 66492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 5 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 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 7 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 7 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 768 KB Output is correct
24 Correct 7 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 5 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 512 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 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 6 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 7 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 7 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 1109 ms 66588 KB Output is correct
49 Correct 1102 ms 66460 KB Output is correct
50 Correct 1104 ms 66460 KB Output is correct
51 Correct 1108 ms 66464 KB Output is correct
52 Correct 1113 ms 66592 KB Output is correct
53 Correct 1130 ms 66492 KB Output is correct
54 Correct 1111 ms 66460 KB Output is correct
55 Correct 1118 ms 66460 KB Output is correct
56 Correct 1112 ms 66564 KB Output is correct
57 Correct 1107 ms 66588 KB Output is correct
58 Correct 1151 ms 66460 KB Output is correct
59 Correct 1150 ms 66460 KB Output is correct
60 Correct 1107 ms 66716 KB Output is correct
61 Correct 1083 ms 66496 KB Output is correct
62 Correct 1091 ms 66460 KB Output is correct
63 Correct 1127 ms 66460 KB Output is correct
64 Correct 1124 ms 66460 KB Output is correct
65 Correct 1129 ms 66492 KB Output is correct
66 Correct 1102 ms 66568 KB Output is correct
67 Correct 1098 ms 66588 KB Output is correct
68 Correct 1088 ms 66492 KB Output is correct
69 Correct 1098 ms 66492 KB Output is correct
70 Correct 1101 ms 66460 KB Output is correct
71 Correct 1110 ms 66456 KB Output is correct
72 Correct 1147 ms 66460 KB Output is correct
73 Correct 1199 ms 66460 KB Output is correct
74 Correct 1143 ms 66620 KB Output is correct
75 Correct 1124 ms 66592 KB Output is correct
76 Correct 1112 ms 66588 KB Output is correct
77 Correct 1175 ms 66592 KB Output is correct
78 Correct 1161 ms 66588 KB Output is correct
79 Correct 1142 ms 66460 KB Output is correct
80 Correct 1149 ms 66460 KB Output is correct
81 Correct 1137 ms 66588 KB Output is correct
82 Correct 1118 ms 66492 KB Output is correct
83 Correct 1107 ms 66456 KB Output is correct
84 Correct 1103 ms 66460 KB Output is correct
85 Correct 1104 ms 66460 KB Output is correct
86 Correct 1106 ms 66636 KB Output is correct
87 Correct 1128 ms 66460 KB Output is correct
88 Correct 1121 ms 66456 KB Output is correct
89 Correct 1134 ms 66492 KB Output is correct
90 Correct 1125 ms 66564 KB Output is correct
91 Correct 1116 ms 66460 KB Output is correct
92 Correct 1145 ms 66460 KB Output is correct
93 Correct 1097 ms 66460 KB Output is correct
94 Correct 1100 ms 66492 KB Output is correct
95 Correct 1143 ms 66492 KB Output is correct
96 Correct 1114 ms 66460 KB Output is correct
97 Correct 1136 ms 66460 KB Output is correct
98 Correct 1111 ms 66464 KB Output is correct
99 Correct 1104 ms 66468 KB Output is correct
100 Incorrect 993 ms 66456 KB Output isn't correct
101 Halted 0 ms 0 KB -