답안 #625574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625574 2022-08-10T15:07:09 Z ansol4328 Bulldozer (JOI17_bulldozer) C++17
100 / 100
956 ms 79112 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;
    uf(int a) : p(a+5,-1) {}
    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;
    }
};

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;
    int cur=0;
    ll ans=max(0LL,seg.qry());
    vector<bool> chk(N+5);
    vector<int> S;
    for(auto slp : F){
        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);
            grp[T.f(p)].pb(inv[p]);
        }
        //re-ordering
        for(int G : tmp){
            sort(grp[G].begin(),grp[G].end());
            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();
        }
        //roll back
        for(int p : S){
            T.p[p]=-1; chk[p]=false;
            seg.updt(inv[p],M[p].se);
        }
        ans=max(ans,seg.qry());
    }
    cout << ans;
    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(; cur<lst.size() && lst[cur].slp==slp ; cur++){
      |               ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 2 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 688 KB Output is correct
8 Correct 1 ms 688 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 688 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 688 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 688 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 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 688 KB Output is correct
22 Correct 2 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 724 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 2 ms 688 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 688 KB Output is correct
31 Correct 2 ms 688 KB Output is correct
32 Correct 3 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 688 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 688 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 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 688 KB Output is correct
22 Correct 2 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 724 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 2 ms 688 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 688 KB Output is correct
31 Correct 2 ms 688 KB Output is correct
32 Correct 3 ms 688 KB Output is correct
33 Correct 922 ms 78880 KB Output is correct
34 Correct 906 ms 78872 KB Output is correct
35 Correct 924 ms 78992 KB Output is correct
36 Correct 892 ms 78892 KB Output is correct
37 Correct 930 ms 78880 KB Output is correct
38 Correct 900 ms 78988 KB Output is correct
39 Correct 905 ms 78988 KB Output is correct
40 Correct 888 ms 78880 KB Output is correct
41 Correct 899 ms 78872 KB Output is correct
42 Correct 908 ms 78912 KB Output is correct
43 Correct 902 ms 78984 KB Output is correct
44 Correct 894 ms 78868 KB Output is correct
45 Correct 956 ms 78912 KB Output is correct
46 Correct 888 ms 78856 KB Output is correct
47 Correct 895 ms 78876 KB Output is correct
48 Correct 883 ms 78872 KB Output is correct
49 Correct 881 ms 78780 KB Output is correct
50 Correct 885 ms 78872 KB Output is correct
51 Correct 899 ms 79000 KB Output is correct
52 Correct 883 ms 78876 KB Output is correct
53 Correct 897 ms 78868 KB Output is correct
54 Correct 888 ms 78836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 688 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 688 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 688 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 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 688 KB Output is correct
22 Correct 2 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 724 KB Output is correct
26 Correct 2 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 2 ms 688 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 688 KB Output is correct
31 Correct 2 ms 688 KB Output is correct
32 Correct 3 ms 688 KB Output is correct
33 Correct 922 ms 78880 KB Output is correct
34 Correct 906 ms 78872 KB Output is correct
35 Correct 924 ms 78992 KB Output is correct
36 Correct 892 ms 78892 KB Output is correct
37 Correct 930 ms 78880 KB Output is correct
38 Correct 900 ms 78988 KB Output is correct
39 Correct 905 ms 78988 KB Output is correct
40 Correct 888 ms 78880 KB Output is correct
41 Correct 899 ms 78872 KB Output is correct
42 Correct 908 ms 78912 KB Output is correct
43 Correct 902 ms 78984 KB Output is correct
44 Correct 894 ms 78868 KB Output is correct
45 Correct 956 ms 78912 KB Output is correct
46 Correct 888 ms 78856 KB Output is correct
47 Correct 895 ms 78876 KB Output is correct
48 Correct 883 ms 78872 KB Output is correct
49 Correct 881 ms 78780 KB Output is correct
50 Correct 885 ms 78872 KB Output is correct
51 Correct 899 ms 79000 KB Output is correct
52 Correct 883 ms 78876 KB Output is correct
53 Correct 897 ms 78868 KB Output is correct
54 Correct 888 ms 78836 KB Output is correct
55 Correct 881 ms 78872 KB Output is correct
56 Correct 896 ms 78860 KB Output is correct
57 Correct 900 ms 78760 KB Output is correct
58 Correct 953 ms 78880 KB Output is correct
59 Correct 900 ms 78860 KB Output is correct
60 Correct 881 ms 78852 KB Output is correct
61 Correct 901 ms 78852 KB Output is correct
62 Correct 911 ms 78876 KB Output is correct
63 Correct 914 ms 78932 KB Output is correct
64 Correct 918 ms 78920 KB Output is correct
65 Correct 893 ms 78860 KB Output is correct
66 Correct 920 ms 78932 KB Output is correct
67 Correct 886 ms 78852 KB Output is correct
68 Correct 911 ms 78884 KB Output is correct
69 Correct 882 ms 78872 KB Output is correct
70 Correct 898 ms 78956 KB Output is correct
71 Correct 885 ms 78900 KB Output is correct
72 Correct 904 ms 78928 KB Output is correct
73 Correct 915 ms 78880 KB Output is correct
74 Correct 881 ms 78916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 2 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 688 KB Output is correct
8 Correct 1 ms 688 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 688 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 688 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 688 KB Output is correct
19 Correct 2 ms 688 KB Output is correct
20 Correct 3 ms 688 KB Output is correct
21 Correct 2 ms 688 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 688 KB Output is correct
24 Correct 2 ms 688 KB Output is correct
25 Correct 2 ms 688 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 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 688 KB Output is correct
37 Correct 2 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 724 KB Output is correct
41 Correct 2 ms 688 KB Output is correct
42 Correct 2 ms 688 KB Output is correct
43 Correct 2 ms 688 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 688 KB Output is correct
46 Correct 2 ms 688 KB Output is correct
47 Correct 3 ms 688 KB Output is correct
48 Correct 922 ms 78880 KB Output is correct
49 Correct 906 ms 78872 KB Output is correct
50 Correct 924 ms 78992 KB Output is correct
51 Correct 892 ms 78892 KB Output is correct
52 Correct 930 ms 78880 KB Output is correct
53 Correct 900 ms 78988 KB Output is correct
54 Correct 905 ms 78988 KB Output is correct
55 Correct 888 ms 78880 KB Output is correct
56 Correct 899 ms 78872 KB Output is correct
57 Correct 908 ms 78912 KB Output is correct
58 Correct 902 ms 78984 KB Output is correct
59 Correct 894 ms 78868 KB Output is correct
60 Correct 956 ms 78912 KB Output is correct
61 Correct 888 ms 78856 KB Output is correct
62 Correct 895 ms 78876 KB Output is correct
63 Correct 883 ms 78872 KB Output is correct
64 Correct 881 ms 78780 KB Output is correct
65 Correct 885 ms 78872 KB Output is correct
66 Correct 899 ms 79000 KB Output is correct
67 Correct 883 ms 78876 KB Output is correct
68 Correct 897 ms 78868 KB Output is correct
69 Correct 888 ms 78836 KB Output is correct
70 Correct 881 ms 78872 KB Output is correct
71 Correct 896 ms 78860 KB Output is correct
72 Correct 900 ms 78760 KB Output is correct
73 Correct 953 ms 78880 KB Output is correct
74 Correct 900 ms 78860 KB Output is correct
75 Correct 881 ms 78852 KB Output is correct
76 Correct 901 ms 78852 KB Output is correct
77 Correct 911 ms 78876 KB Output is correct
78 Correct 914 ms 78932 KB Output is correct
79 Correct 918 ms 78920 KB Output is correct
80 Correct 893 ms 78860 KB Output is correct
81 Correct 920 ms 78932 KB Output is correct
82 Correct 886 ms 78852 KB Output is correct
83 Correct 911 ms 78884 KB Output is correct
84 Correct 882 ms 78872 KB Output is correct
85 Correct 898 ms 78956 KB Output is correct
86 Correct 885 ms 78900 KB Output is correct
87 Correct 904 ms 78928 KB Output is correct
88 Correct 915 ms 78880 KB Output is correct
89 Correct 881 ms 78916 KB Output is correct
90 Correct 889 ms 78992 KB Output is correct
91 Correct 911 ms 79000 KB Output is correct
92 Correct 883 ms 78872 KB Output is correct
93 Correct 929 ms 78872 KB Output is correct
94 Correct 886 ms 78960 KB Output is correct
95 Correct 936 ms 78872 KB Output is correct
96 Correct 890 ms 78932 KB Output is correct
97 Correct 885 ms 78872 KB Output is correct
98 Correct 911 ms 78864 KB Output is correct
99 Correct 923 ms 78864 KB Output is correct
100 Correct 550 ms 78852 KB Output is correct
101 Correct 543 ms 78932 KB Output is correct
102 Correct 511 ms 78860 KB Output is correct
103 Correct 503 ms 78888 KB Output is correct
104 Correct 517 ms 78900 KB Output is correct
105 Correct 605 ms 78988 KB Output is correct
106 Correct 600 ms 78892 KB Output is correct
107 Correct 594 ms 78860 KB Output is correct
108 Correct 633 ms 78936 KB Output is correct
109 Correct 612 ms 78876 KB Output is correct
110 Correct 641 ms 79020 KB Output is correct
111 Correct 635 ms 78980 KB Output is correct
112 Correct 681 ms 78984 KB Output is correct
113 Correct 642 ms 79024 KB Output is correct
114 Correct 648 ms 79112 KB Output is correct
115 Correct 658 ms 78988 KB Output is correct
116 Correct 627 ms 78992 KB Output is correct
117 Correct 629 ms 79012 KB Output is correct
118 Correct 637 ms 78988 KB Output is correct
119 Correct 660 ms 78984 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 1 ms 340 KB Output is correct
122 Correct 908 ms 78876 KB Output is correct
123 Correct 888 ms 78936 KB Output is correct
124 Correct 888 ms 78872 KB Output is correct
125 Correct 893 ms 79000 KB Output is correct
126 Correct 880 ms 79040 KB Output is correct
127 Correct 882 ms 78888 KB Output is correct
128 Correct 890 ms 78916 KB Output is correct
129 Correct 863 ms 78768 KB Output is correct
130 Correct 881 ms 78860 KB Output is correct
131 Correct 880 ms 78912 KB Output is correct
132 Correct 949 ms 79040 KB Output is correct
133 Correct 886 ms 78864 KB Output is correct