답안 #625559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625559 2022-08-10T14:53:14 Z ansol4328 Bulldozer (JOI17_bulldozer) C++17
100 / 100
1182 ms 79284 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

struct SegTree{
    struct node{
        ll L, R, sum, mx;
    };
    vector<node> tree;
    int base;
    SegTree(int a){
        for(base=1 ; base<a ; base<<=1);
        tree.resize(base*2);
        base--;
    }
    node add(node &lhs, node &rhs){
        node ret;
        ret.sum=lhs.sum+rhs.sum;
        ret.L=max(lhs.L,lhs.sum+rhs.L);
        ret.R=max(rhs.R,rhs.sum+lhs.R);
        ret.mx=max({lhs.R+rhs.L, lhs.mx, rhs.mx});
        return ret;
    }
    void updt(int i, ll v){
        tree[i+=base]={v,v,v,v};
        for(i>>=1 ; i ; i>>=1) tree[i]=add(tree[i*2],tree[i*2+1]);
    }
    ll qry(){ return tree[1].mx; }
};

struct frac{
    ll a, b;
    bool operator< (const frac &rhs) const{
        return a*rhs.b>rhs.a*b;
    }
    bool operator== (const frac &rhs) const{
        return a*rhs.b==rhs.a*b;
    }
};

struct line{
    frac slp;
    int p1, p2;
    bool operator< (const line &rhs) const{
        return slp<rhs.slp;
    }
};

struct uf{
    vector<int> p;
    vector<ll> w;
    uf(int a) : p(a+5,-1), w(a+5,0) {}
    int f(int a){ return p[a]==-1 ? a : p[a]=f(p[a]); }
    void u(int x, int y){
        x=f(x), y=f(y);
        if(x==y) return;
        p[x]=y; w[y]+=w[x];
    }
};

int N;
pair<P,ll> M[2005];
int id[2005], inv[2005];
//id = sorted state, inv = inverse of id
vector<line> lst;
vector<int> grp[2005];

void fastio(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
}

int main(){
    fastio();
    cin >> N;
    for(int i=1 ; i<=N ; i++){
        cin >> M[i].fi.fi >> M[i].fi.se >> M[i].se;
    }
    if(N==1){
        cout << max(0LL,M[1].se) << '\n'; return 0;
    }
    vector<frac> F;
    sort(M+1,M+1+N);
    for(int i=1 ; i<=N ; i++){
        for(int j=i+1 ; j<=N ; j++){
            lst.pb({{M[i].fi.se-M[j].fi.se, M[i].fi.fi-M[j].fi.fi},i,j});
            F.pb(lst.back().slp);
        }
    }
    sort(lst.begin(),lst.end());
    sort(F.begin(),F.end());
    F.erase(unique(F.begin(),F.end()),F.end());

    SegTree seg(N);
    uf T(N);
    for(int i=1 ; i<=N ; i++) seg.updt(i,M[i].se), id[i]=inv[i]=i, T.w[i]=M[i].se;
    int cur=0;
    ll ans=0;
    vector<bool> chk(N+5);
    vector<int> S;
    for(auto slp : F){
//        cout << slp.a << '/' << slp.b << ' ' ;
        S.clear();
        for(; cur<lst.size() && lst[cur].slp==slp ; cur++){
            //union
            T.u(lst[cur].p1,lst[cur].p2);
            if(!chk[lst[cur].p1]) chk[lst[cur].p1]=true, S.pb(lst[cur].p1);
            if(!chk[lst[cur].p2]) chk[lst[cur].p2]=true, S.pb(lst[cur].p2);
        }
        vector<int> tmp;
        for(int p : S){
            if(T.f(p)==p) tmp.pb(p), seg.updt(inv[p],T.w[p]);
            else seg.updt(inv[p],0);
            grp[T.f(p)].pb(inv[p]);
        }
        ans=max(ans,seg.qry());
//        cout << ans << ' ' << seg.qry() << '\n';

        //re-ordering
        for(int G : tmp){
            sort(grp[G].begin(),grp[G].end());
            // for(int t : grp[G]) cout << t << ' ';
            // cout << '\n';
            for(int i=0, j=(int)grp[G].size()-1 ; i<j ; i++, j--){
                int x=grp[G][i], y=grp[G][j];
                swap(inv[id[x]],inv[id[y]]);
                swap(id[x],id[y]);
            }
            grp[G].clear();
        }
        // for(int i=1 ; i<=N ; i++) cout << id[i] << ' ';
        // cout << '\n';
        //roll back
        for(int p : S){
            T.w[p]=M[p].se; T.p[p]=-1;
            chk[p]=false;
            seg.updt(inv[p],T.w[p]);
        }
        ans=max(ans,seg.qry());
//        assert(S.size()==2);
    }
    ans=max(ans,seg.qry());
    cout << ans;
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:108:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         for(; cur<lst.size() && lst[cur].slp==slp ; cur++){
      |               ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 688 KB Output is correct
2 Correct 1 ms 688 KB Output is correct
3 Correct 1 ms 688 KB Output is correct
4 Correct 1 ms 688 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 688 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 688 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 2 ms 688 KB Output is correct
3 Correct 2 ms 688 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 2 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 2 ms 688 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 2 ms 688 KB Output is correct
3 Correct 2 ms 688 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 2 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 2 ms 688 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 1130 ms 78872 KB Output is correct
34 Correct 1159 ms 78948 KB Output is correct
35 Correct 1125 ms 79032 KB Output is correct
36 Correct 1117 ms 78984 KB Output is correct
37 Correct 1121 ms 78924 KB Output is correct
38 Correct 1127 ms 78928 KB Output is correct
39 Correct 1108 ms 78976 KB Output is correct
40 Correct 1114 ms 78960 KB Output is correct
41 Correct 1124 ms 78920 KB Output is correct
42 Correct 1114 ms 78924 KB Output is correct
43 Correct 1115 ms 78928 KB Output is correct
44 Correct 1083 ms 78944 KB Output is correct
45 Correct 1101 ms 78940 KB Output is correct
46 Correct 1134 ms 78956 KB Output is correct
47 Correct 1097 ms 79008 KB Output is correct
48 Correct 1096 ms 78920 KB Output is correct
49 Correct 1105 ms 79200 KB Output is correct
50 Correct 1114 ms 78920 KB Output is correct
51 Correct 1103 ms 78924 KB Output is correct
52 Correct 1112 ms 78928 KB Output is correct
53 Correct 1117 ms 78920 KB Output is correct
54 Correct 1153 ms 78860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 2 ms 688 KB Output is correct
3 Correct 2 ms 688 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 3 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 2 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 2 ms 688 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 1130 ms 78872 KB Output is correct
34 Correct 1159 ms 78948 KB Output is correct
35 Correct 1125 ms 79032 KB Output is correct
36 Correct 1117 ms 78984 KB Output is correct
37 Correct 1121 ms 78924 KB Output is correct
38 Correct 1127 ms 78928 KB Output is correct
39 Correct 1108 ms 78976 KB Output is correct
40 Correct 1114 ms 78960 KB Output is correct
41 Correct 1124 ms 78920 KB Output is correct
42 Correct 1114 ms 78924 KB Output is correct
43 Correct 1115 ms 78928 KB Output is correct
44 Correct 1083 ms 78944 KB Output is correct
45 Correct 1101 ms 78940 KB Output is correct
46 Correct 1134 ms 78956 KB Output is correct
47 Correct 1097 ms 79008 KB Output is correct
48 Correct 1096 ms 78920 KB Output is correct
49 Correct 1105 ms 79200 KB Output is correct
50 Correct 1114 ms 78920 KB Output is correct
51 Correct 1103 ms 78924 KB Output is correct
52 Correct 1112 ms 78928 KB Output is correct
53 Correct 1117 ms 78920 KB Output is correct
54 Correct 1153 ms 78860 KB Output is correct
55 Correct 1141 ms 78924 KB Output is correct
56 Correct 1094 ms 78920 KB Output is correct
57 Correct 1148 ms 78960 KB Output is correct
58 Correct 1147 ms 78956 KB Output is correct
59 Correct 1113 ms 78968 KB Output is correct
60 Correct 1109 ms 78920 KB Output is correct
61 Correct 1122 ms 79040 KB Output is correct
62 Correct 1182 ms 78952 KB Output is correct
63 Correct 1124 ms 79048 KB Output is correct
64 Correct 1116 ms 78924 KB Output is correct
65 Correct 1117 ms 78860 KB Output is correct
66 Correct 1123 ms 78964 KB Output is correct
67 Correct 1104 ms 79056 KB Output is correct
68 Correct 1104 ms 79072 KB Output is correct
69 Correct 1103 ms 79036 KB Output is correct
70 Correct 1109 ms 78968 KB Output is correct
71 Correct 1097 ms 78964 KB Output is correct
72 Correct 1106 ms 78972 KB Output is correct
73 Correct 1100 ms 78920 KB Output is correct
74 Correct 1101 ms 78968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 688 KB Output is correct
2 Correct 1 ms 688 KB Output is correct
3 Correct 1 ms 688 KB Output is correct
4 Correct 1 ms 688 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 688 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 688 KB Output is correct
9 Correct 1 ms 688 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 2 ms 688 KB Output is correct
18 Correct 2 ms 688 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 688 KB Output is correct
21 Correct 2 ms 688 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 3 ms 688 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 3 ms 688 KB Output is correct
38 Correct 2 ms 688 KB Output is correct
39 Correct 3 ms 688 KB Output is correct
40 Correct 2 ms 688 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 1130 ms 78872 KB Output is correct
49 Correct 1159 ms 78948 KB Output is correct
50 Correct 1125 ms 79032 KB Output is correct
51 Correct 1117 ms 78984 KB Output is correct
52 Correct 1121 ms 78924 KB Output is correct
53 Correct 1127 ms 78928 KB Output is correct
54 Correct 1108 ms 78976 KB Output is correct
55 Correct 1114 ms 78960 KB Output is correct
56 Correct 1124 ms 78920 KB Output is correct
57 Correct 1114 ms 78924 KB Output is correct
58 Correct 1115 ms 78928 KB Output is correct
59 Correct 1083 ms 78944 KB Output is correct
60 Correct 1101 ms 78940 KB Output is correct
61 Correct 1134 ms 78956 KB Output is correct
62 Correct 1097 ms 79008 KB Output is correct
63 Correct 1096 ms 78920 KB Output is correct
64 Correct 1105 ms 79200 KB Output is correct
65 Correct 1114 ms 78920 KB Output is correct
66 Correct 1103 ms 78924 KB Output is correct
67 Correct 1112 ms 78928 KB Output is correct
68 Correct 1117 ms 78920 KB Output is correct
69 Correct 1153 ms 78860 KB Output is correct
70 Correct 1141 ms 78924 KB Output is correct
71 Correct 1094 ms 78920 KB Output is correct
72 Correct 1148 ms 78960 KB Output is correct
73 Correct 1147 ms 78956 KB Output is correct
74 Correct 1113 ms 78968 KB Output is correct
75 Correct 1109 ms 78920 KB Output is correct
76 Correct 1122 ms 79040 KB Output is correct
77 Correct 1182 ms 78952 KB Output is correct
78 Correct 1124 ms 79048 KB Output is correct
79 Correct 1116 ms 78924 KB Output is correct
80 Correct 1117 ms 78860 KB Output is correct
81 Correct 1123 ms 78964 KB Output is correct
82 Correct 1104 ms 79056 KB Output is correct
83 Correct 1104 ms 79072 KB Output is correct
84 Correct 1103 ms 79036 KB Output is correct
85 Correct 1109 ms 78968 KB Output is correct
86 Correct 1097 ms 78964 KB Output is correct
87 Correct 1106 ms 78972 KB Output is correct
88 Correct 1100 ms 78920 KB Output is correct
89 Correct 1101 ms 78968 KB Output is correct
90 Correct 1153 ms 78944 KB Output is correct
91 Correct 1119 ms 78944 KB Output is correct
92 Correct 1143 ms 78952 KB Output is correct
93 Correct 1128 ms 78928 KB Output is correct
94 Correct 1100 ms 79052 KB Output is correct
95 Correct 1098 ms 78948 KB Output is correct
96 Correct 1135 ms 78928 KB Output is correct
97 Correct 1096 ms 78944 KB Output is correct
98 Correct 1118 ms 78988 KB Output is correct
99 Correct 1091 ms 78956 KB Output is correct
100 Correct 613 ms 78920 KB Output is correct
101 Correct 612 ms 78924 KB Output is correct
102 Correct 611 ms 78836 KB Output is correct
103 Correct 605 ms 78812 KB Output is correct
104 Correct 624 ms 78964 KB Output is correct
105 Correct 755 ms 79100 KB Output is correct
106 Correct 768 ms 78968 KB Output is correct
107 Correct 740 ms 78856 KB Output is correct
108 Correct 731 ms 78924 KB Output is correct
109 Correct 744 ms 78924 KB Output is correct
110 Correct 774 ms 79056 KB Output is correct
111 Correct 768 ms 79064 KB Output is correct
112 Correct 800 ms 79052 KB Output is correct
113 Correct 771 ms 79156 KB Output is correct
114 Correct 797 ms 79104 KB Output is correct
115 Correct 787 ms 79116 KB Output is correct
116 Correct 846 ms 79188 KB Output is correct
117 Correct 830 ms 79148 KB Output is correct
118 Correct 850 ms 79284 KB Output is correct
119 Correct 809 ms 78972 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 1 ms 340 KB Output is correct
122 Correct 1172 ms 78964 KB Output is correct
123 Correct 1127 ms 78928 KB Output is correct
124 Correct 1107 ms 78924 KB Output is correct
125 Correct 1113 ms 79004 KB Output is correct
126 Correct 1082 ms 78888 KB Output is correct
127 Correct 1096 ms 78960 KB Output is correct
128 Correct 1075 ms 78928 KB Output is correct
129 Correct 1088 ms 79044 KB Output is correct
130 Correct 1093 ms 78884 KB Output is correct
131 Correct 1088 ms 79060 KB Output is correct
132 Correct 1089 ms 78956 KB Output is correct
133 Correct 1089 ms 78920 KB Output is correct