Submission #476763

# Submission time Handle Problem Language Result Execution time Memory
476763 2021-09-28T13:34:07 Z nicolaalexandra Bulldozer (JOI17_bulldozer) C++14
100 / 100
1245 ms 49884 KB
#include <bits/stdc++.h>
#define DIM 2010
#define INF 2000000000
using namespace std;

struct punct{
    long long x,y,cost;
} v[DIM];

struct panta{
    long long a,b;
    int idx,idx2;
};

vector <panta> p;

struct segment_tree{
    long long best,pref,suf,sum;
} aint[DIM*4];

int n,i,j,k;
long long sol;
int poz[DIM];

void update_nod (int nod){
    int fiu_st = nod<<1, fiu_dr = (nod<<1)|1;
    aint[nod].sum = aint[fiu_st].sum + aint[fiu_dr].sum;
    aint[nod].pref = max (aint[fiu_st].pref, aint[fiu_st].sum + aint[fiu_dr].pref);
    aint[nod].suf = max (aint[fiu_dr].suf,aint[fiu_dr].sum + aint[fiu_st].suf);
    aint[nod].best = max (aint[fiu_st].best,aint[fiu_dr].best);
    aint[nod].best = max (aint[nod].best,aint[fiu_st].suf + aint[fiu_dr].pref);
    aint[nod].best = max (aint[nod].best,max(aint[nod].pref,aint[nod].suf));
}

void build (int nod, int st, int dr){
    if (st == dr){
        aint[nod].sum = v[st].cost;
        aint[nod].pref = v[st].cost;
        aint[nod].suf = v[st].cost;
        aint[nod].best = v[st].cost;
        return;
    }
    int mid = (st+dr)>>1;
    build (nod<<1,st,mid);
    build ((nod<<1)|1,mid+1,dr);
    update_nod(nod);
}

void update (int nod, int st, int dr, int poz, int val){
    if (st == dr){
        aint[nod].sum = val;
        aint[nod].pref = val;
        aint[nod].suf = val;
        aint[nod].best = val;
        return;
    }
    int mid = (st+dr)>>1;
    if (poz <= mid)
        update (nod<<1,st,mid,poz,val);
    else update ((nod<<1)|1,mid+1,dr,poz,val);

    update_nod(nod);
}


inline int cmp (punct a, punct b){
    if (a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}

inline int cmp2 (panta p1, panta p2){

    if (p1.a * p2.b == p1.b * p2.a){
        if (p1.idx == p2.idx)
            return p1.idx2 < p2.idx2;
        return p1.idx < p2.idx;
    }

    return p1.a * p2.b < p1.b * p2.a;

}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;
    for (i=1;i<=n;i++)
        cin>>v[i].x>>v[i].y>>v[i].cost;

    sort (v+1,v+n+1,cmp);

    for (i=1;i<=n;i++)
        for (j=i+1;j<=n;j++)
            p.push_back({v[j].y-v[i].y,v[j].x-v[i].x,i,j});

    sort (p.begin(),p.end(),cmp2);


    for (i=1;i<=n;i++)
        poz[i] = i;

    build (1,1,n);

    sol = max(0LL,aint[1].best);

    i = 0;
    while (i < p.size()){

        j = i;
        while (j < p.size() && p[i].a * p[j].b == p[i].b * p[j].a){

            update (1,1,n,poz[p[j].idx2], v[ p[j].idx ].cost);

            update (1,1,n,poz[p[j].idx],v[ p[j].idx2 ].cost);

            swap (poz[p[j].idx],poz[p[j].idx2]);

            j++;
        }

        sol = max (sol,aint[1].best);
        i = j;

    }

    cout<<sol;


    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:110:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<panta>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     while (i < p.size()){
      |            ~~^~~~~~~~~~
bulldozer.cpp:113:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<panta>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         while (j < p.size() && p[i].a * p[j].b == p[i].b * p[j].a){
      |                ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 1128 ms 49680 KB Output is correct
34 Correct 1156 ms 49832 KB Output is correct
35 Correct 1092 ms 49684 KB Output is correct
36 Correct 1108 ms 49784 KB Output is correct
37 Correct 1097 ms 49796 KB Output is correct
38 Correct 1245 ms 49776 KB Output is correct
39 Correct 1112 ms 49824 KB Output is correct
40 Correct 1169 ms 49800 KB Output is correct
41 Correct 1163 ms 49820 KB Output is correct
42 Correct 1146 ms 49840 KB Output is correct
43 Correct 1102 ms 49812 KB Output is correct
44 Correct 1090 ms 49864 KB Output is correct
45 Correct 1081 ms 49808 KB Output is correct
46 Correct 1093 ms 49784 KB Output is correct
47 Correct 1058 ms 49832 KB Output is correct
48 Correct 1127 ms 49808 KB Output is correct
49 Correct 1109 ms 49808 KB Output is correct
50 Correct 1126 ms 49808 KB Output is correct
51 Correct 1111 ms 49780 KB Output is correct
52 Correct 1074 ms 49696 KB Output is correct
53 Correct 1090 ms 49808 KB Output is correct
54 Correct 1119 ms 49804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 2 ms 588 KB Output is correct
33 Correct 1128 ms 49680 KB Output is correct
34 Correct 1156 ms 49832 KB Output is correct
35 Correct 1092 ms 49684 KB Output is correct
36 Correct 1108 ms 49784 KB Output is correct
37 Correct 1097 ms 49796 KB Output is correct
38 Correct 1245 ms 49776 KB Output is correct
39 Correct 1112 ms 49824 KB Output is correct
40 Correct 1169 ms 49800 KB Output is correct
41 Correct 1163 ms 49820 KB Output is correct
42 Correct 1146 ms 49840 KB Output is correct
43 Correct 1102 ms 49812 KB Output is correct
44 Correct 1090 ms 49864 KB Output is correct
45 Correct 1081 ms 49808 KB Output is correct
46 Correct 1093 ms 49784 KB Output is correct
47 Correct 1058 ms 49832 KB Output is correct
48 Correct 1127 ms 49808 KB Output is correct
49 Correct 1109 ms 49808 KB Output is correct
50 Correct 1126 ms 49808 KB Output is correct
51 Correct 1111 ms 49780 KB Output is correct
52 Correct 1074 ms 49696 KB Output is correct
53 Correct 1090 ms 49808 KB Output is correct
54 Correct 1119 ms 49804 KB Output is correct
55 Correct 1233 ms 49732 KB Output is correct
56 Correct 1111 ms 49808 KB Output is correct
57 Correct 1090 ms 49812 KB Output is correct
58 Correct 1169 ms 49744 KB Output is correct
59 Correct 1130 ms 49708 KB Output is correct
60 Correct 1095 ms 49808 KB Output is correct
61 Correct 1111 ms 49784 KB Output is correct
62 Correct 1083 ms 49808 KB Output is correct
63 Correct 1078 ms 49776 KB Output is correct
64 Correct 1090 ms 49808 KB Output is correct
65 Correct 1078 ms 49812 KB Output is correct
66 Correct 1083 ms 49788 KB Output is correct
67 Correct 1099 ms 49784 KB Output is correct
68 Correct 1094 ms 49832 KB Output is correct
69 Correct 1109 ms 49772 KB Output is correct
70 Correct 1160 ms 49804 KB Output is correct
71 Correct 1123 ms 49832 KB Output is correct
72 Correct 1086 ms 49800 KB Output is correct
73 Correct 1116 ms 49808 KB Output is correct
74 Correct 1111 ms 49808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 2 ms 588 KB Output is correct
37 Correct 2 ms 588 KB Output is correct
38 Correct 2 ms 588 KB Output is correct
39 Correct 2 ms 588 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 588 KB Output is correct
42 Correct 2 ms 588 KB Output is correct
43 Correct 2 ms 588 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 2 ms 588 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 2 ms 588 KB Output is correct
48 Correct 1128 ms 49680 KB Output is correct
49 Correct 1156 ms 49832 KB Output is correct
50 Correct 1092 ms 49684 KB Output is correct
51 Correct 1108 ms 49784 KB Output is correct
52 Correct 1097 ms 49796 KB Output is correct
53 Correct 1245 ms 49776 KB Output is correct
54 Correct 1112 ms 49824 KB Output is correct
55 Correct 1169 ms 49800 KB Output is correct
56 Correct 1163 ms 49820 KB Output is correct
57 Correct 1146 ms 49840 KB Output is correct
58 Correct 1102 ms 49812 KB Output is correct
59 Correct 1090 ms 49864 KB Output is correct
60 Correct 1081 ms 49808 KB Output is correct
61 Correct 1093 ms 49784 KB Output is correct
62 Correct 1058 ms 49832 KB Output is correct
63 Correct 1127 ms 49808 KB Output is correct
64 Correct 1109 ms 49808 KB Output is correct
65 Correct 1126 ms 49808 KB Output is correct
66 Correct 1111 ms 49780 KB Output is correct
67 Correct 1074 ms 49696 KB Output is correct
68 Correct 1090 ms 49808 KB Output is correct
69 Correct 1119 ms 49804 KB Output is correct
70 Correct 1233 ms 49732 KB Output is correct
71 Correct 1111 ms 49808 KB Output is correct
72 Correct 1090 ms 49812 KB Output is correct
73 Correct 1169 ms 49744 KB Output is correct
74 Correct 1130 ms 49708 KB Output is correct
75 Correct 1095 ms 49808 KB Output is correct
76 Correct 1111 ms 49784 KB Output is correct
77 Correct 1083 ms 49808 KB Output is correct
78 Correct 1078 ms 49776 KB Output is correct
79 Correct 1090 ms 49808 KB Output is correct
80 Correct 1078 ms 49812 KB Output is correct
81 Correct 1083 ms 49788 KB Output is correct
82 Correct 1099 ms 49784 KB Output is correct
83 Correct 1094 ms 49832 KB Output is correct
84 Correct 1109 ms 49772 KB Output is correct
85 Correct 1160 ms 49804 KB Output is correct
86 Correct 1123 ms 49832 KB Output is correct
87 Correct 1086 ms 49800 KB Output is correct
88 Correct 1116 ms 49808 KB Output is correct
89 Correct 1111 ms 49808 KB Output is correct
90 Correct 1212 ms 49768 KB Output is correct
91 Correct 1114 ms 49788 KB Output is correct
92 Correct 1116 ms 49884 KB Output is correct
93 Correct 1086 ms 49800 KB Output is correct
94 Correct 1088 ms 49812 KB Output is correct
95 Correct 1088 ms 49688 KB Output is correct
96 Correct 1093 ms 49784 KB Output is correct
97 Correct 1120 ms 49808 KB Output is correct
98 Correct 1106 ms 49732 KB Output is correct
99 Correct 1071 ms 49808 KB Output is correct
100 Correct 899 ms 49680 KB Output is correct
101 Correct 904 ms 49696 KB Output is correct
102 Correct 919 ms 49656 KB Output is correct
103 Correct 900 ms 49784 KB Output is correct
104 Correct 915 ms 49768 KB Output is correct
105 Correct 946 ms 49656 KB Output is correct
106 Correct 992 ms 49692 KB Output is correct
107 Correct 933 ms 49680 KB Output is correct
108 Correct 934 ms 49692 KB Output is correct
109 Correct 933 ms 49692 KB Output is correct
110 Correct 1000 ms 49704 KB Output is correct
111 Correct 1006 ms 49656 KB Output is correct
112 Correct 1008 ms 49692 KB Output is correct
113 Correct 1000 ms 49680 KB Output is correct
114 Correct 1014 ms 49680 KB Output is correct
115 Correct 1004 ms 49680 KB Output is correct
116 Correct 1016 ms 49680 KB Output is correct
117 Correct 1022 ms 49680 KB Output is correct
118 Correct 995 ms 49680 KB Output is correct
119 Correct 1016 ms 49756 KB Output is correct
120 Correct 1 ms 204 KB Output is correct
121 Correct 0 ms 204 KB Output is correct
122 Correct 1094 ms 49804 KB Output is correct
123 Correct 1090 ms 49808 KB Output is correct
124 Correct 1104 ms 49784 KB Output is correct
125 Correct 1097 ms 49756 KB Output is correct
126 Correct 1070 ms 49720 KB Output is correct
127 Correct 1073 ms 49804 KB Output is correct
128 Correct 1069 ms 49788 KB Output is correct
129 Correct 1078 ms 49772 KB Output is correct
130 Correct 1068 ms 49808 KB Output is correct
131 Correct 1080 ms 49812 KB Output is correct
132 Correct 1087 ms 49808 KB Output is correct
133 Correct 1058 ms 49816 KB Output is correct