Submission #156398

# Submission time Handle Problem Language Result Execution time Memory
156398 2019-10-05T12:57:35 Z georgerapeanu Bulldozer (JOI17_bulldozer) C++11
100 / 100
1294 ms 32216 KB
#include <cstdio>
#include <algorithm>

using namespace std;

struct point_t{
    int x,y,c;

    bool operator < (const point_t &other)const{
        if(y != other.y){
            return y < other.y;
        }
        return x < other.x;
    }
};

struct line_t{
    int a,b;
    int i,j;
};

struct node_t{
    long long pref_sum;
    long long suff_sum;
    long long best_sum;
    long long total_sum;

    node_t(long long a = 0LL){
        pref_sum = max(a,0LL);
        suff_sum = max(a,0LL);
        total_sum = a;
        best_sum = max(a,0LL);
    }

    node_t operator + (const node_t &other)const{
        node_t ans;
        ans.pref_sum = max(this->pref_sum,this->total_sum + other.pref_sum);
        ans.suff_sum = max(other.suff_sum,other.total_sum + this->suff_sum);
        ans.total_sum = this->total_sum + other.total_sum;
        ans.best_sum = max(max(this->best_sum,other.best_sum),this->suff_sum + other.pref_sum);
        return ans;
    }
};

int n;
point_t v[2005];
int pos[2005];
line_t lines[2000 * 2000 + 5];
node_t aint[8005];

void build(int nod,int st,int dr){

    if(st == dr){
        aint[nod] = node_t(v[st].c);
        return ;
    }

    int mid = (st + dr) / 2;

    build(nod * 2,st,mid);
    build(nod * 2 + 1,mid + 1,dr);

    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
}

void update(int nod,int st,int dr,int pos,int val){
    if(dr < pos || st > pos){
        return ;
    }

    if(st == dr){
        aint[nod] = node_t(val);
        return ;
    }

    int mid = (st + dr) / 2;

    update(nod * 2,st,mid,pos,val);
    update(nod * 2 + 1,mid + 1,dr,pos,val);

    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
}

int main(){

    scanf("%d",&n);

    for(int i = 1;i <= n;i++){
        scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].c);
    }

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

    int len = 0;

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

    sort(lines + 1,lines + 1 + len,
            [&](line_t &a,line_t & b){
                if(1LL * a.a * b.b != 1LL * b.a * a.b){
                    return 1LL * a.a * b.b > 1LL * b.a * a.b;
                }
                if(a.i != b.i){
                    return a.i < b.i;
                }
                return a.j < b.j;
             });

    for(int i = 1;i <= n;i++){
        pos[i] = i;
    }

    build(1,1,n);

    long long ans = aint[1].best_sum;

    for(int i = 1;i <= len;i++){
        swap(pos[lines[i].i],pos[lines[i].j]);
        update(1,1,n,pos[lines[i].i],v[lines[i].i].c);
        update(1,1,n,pos[lines[i].j],v[lines[i].j].c);
        if(i == len || (1LL * lines[i].a * lines[i + 1].b > 1LL * lines[i + 1].a * lines[i].b)){
            ans = max(ans,aint[1].best_sum);
        }
    }

    printf("%lld\n",ans);

    return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
bulldozer.cpp:89:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 1259 ms 31992 KB Output is correct
34 Correct 1260 ms 31928 KB Output is correct
35 Correct 1258 ms 32128 KB Output is correct
36 Correct 1253 ms 31864 KB Output is correct
37 Correct 1273 ms 31916 KB Output is correct
38 Correct 1251 ms 31992 KB Output is correct
39 Correct 1257 ms 31992 KB Output is correct
40 Correct 1265 ms 31968 KB Output is correct
41 Correct 1264 ms 31992 KB Output is correct
42 Correct 1251 ms 31992 KB Output is correct
43 Correct 1247 ms 31920 KB Output is correct
44 Correct 1236 ms 31916 KB Output is correct
45 Correct 1237 ms 31924 KB Output is correct
46 Correct 1251 ms 31940 KB Output is correct
47 Correct 1248 ms 32120 KB Output is correct
48 Correct 1245 ms 31916 KB Output is correct
49 Correct 1243 ms 31920 KB Output is correct
50 Correct 1257 ms 31992 KB Output is correct
51 Correct 1236 ms 31908 KB Output is correct
52 Correct 1244 ms 31964 KB Output is correct
53 Correct 1240 ms 31964 KB Output is correct
54 Correct 1237 ms 31964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 500 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 4 ms 632 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 632 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 1259 ms 31992 KB Output is correct
34 Correct 1260 ms 31928 KB Output is correct
35 Correct 1258 ms 32128 KB Output is correct
36 Correct 1253 ms 31864 KB Output is correct
37 Correct 1273 ms 31916 KB Output is correct
38 Correct 1251 ms 31992 KB Output is correct
39 Correct 1257 ms 31992 KB Output is correct
40 Correct 1265 ms 31968 KB Output is correct
41 Correct 1264 ms 31992 KB Output is correct
42 Correct 1251 ms 31992 KB Output is correct
43 Correct 1247 ms 31920 KB Output is correct
44 Correct 1236 ms 31916 KB Output is correct
45 Correct 1237 ms 31924 KB Output is correct
46 Correct 1251 ms 31940 KB Output is correct
47 Correct 1248 ms 32120 KB Output is correct
48 Correct 1245 ms 31916 KB Output is correct
49 Correct 1243 ms 31920 KB Output is correct
50 Correct 1257 ms 31992 KB Output is correct
51 Correct 1236 ms 31908 KB Output is correct
52 Correct 1244 ms 31964 KB Output is correct
53 Correct 1240 ms 31964 KB Output is correct
54 Correct 1237 ms 31964 KB Output is correct
55 Correct 1245 ms 32092 KB Output is correct
56 Correct 1272 ms 31924 KB Output is correct
57 Correct 1265 ms 32040 KB Output is correct
58 Correct 1256 ms 32040 KB Output is correct
59 Correct 1263 ms 31964 KB Output is correct
60 Correct 1252 ms 31864 KB Output is correct
61 Correct 1262 ms 31928 KB Output is correct
62 Correct 1263 ms 31992 KB Output is correct
63 Correct 1250 ms 31928 KB Output is correct
64 Correct 1249 ms 31924 KB Output is correct
65 Correct 1243 ms 32040 KB Output is correct
66 Correct 1269 ms 31956 KB Output is correct
67 Correct 1294 ms 32044 KB Output is correct
68 Correct 1259 ms 31920 KB Output is correct
69 Correct 1267 ms 31928 KB Output is correct
70 Correct 1256 ms 31944 KB Output is correct
71 Correct 1250 ms 32120 KB Output is correct
72 Correct 1257 ms 31916 KB Output is correct
73 Correct 1259 ms 32036 KB Output is correct
74 Correct 1256 ms 32044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 508 KB Output is correct
16 Correct 4 ms 632 KB Output is correct
17 Correct 4 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 4 ms 760 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 2 ms 632 KB Output is correct
27 Correct 2 ms 500 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 632 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 4 ms 632 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 4 ms 632 KB Output is correct
40 Correct 4 ms 632 KB Output is correct
41 Correct 5 ms 632 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 4 ms 632 KB Output is correct
44 Correct 4 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 4 ms 632 KB Output is correct
47 Correct 4 ms 760 KB Output is correct
48 Correct 1259 ms 31992 KB Output is correct
49 Correct 1260 ms 31928 KB Output is correct
50 Correct 1258 ms 32128 KB Output is correct
51 Correct 1253 ms 31864 KB Output is correct
52 Correct 1273 ms 31916 KB Output is correct
53 Correct 1251 ms 31992 KB Output is correct
54 Correct 1257 ms 31992 KB Output is correct
55 Correct 1265 ms 31968 KB Output is correct
56 Correct 1264 ms 31992 KB Output is correct
57 Correct 1251 ms 31992 KB Output is correct
58 Correct 1247 ms 31920 KB Output is correct
59 Correct 1236 ms 31916 KB Output is correct
60 Correct 1237 ms 31924 KB Output is correct
61 Correct 1251 ms 31940 KB Output is correct
62 Correct 1248 ms 32120 KB Output is correct
63 Correct 1245 ms 31916 KB Output is correct
64 Correct 1243 ms 31920 KB Output is correct
65 Correct 1257 ms 31992 KB Output is correct
66 Correct 1236 ms 31908 KB Output is correct
67 Correct 1244 ms 31964 KB Output is correct
68 Correct 1240 ms 31964 KB Output is correct
69 Correct 1237 ms 31964 KB Output is correct
70 Correct 1245 ms 32092 KB Output is correct
71 Correct 1272 ms 31924 KB Output is correct
72 Correct 1265 ms 32040 KB Output is correct
73 Correct 1256 ms 32040 KB Output is correct
74 Correct 1263 ms 31964 KB Output is correct
75 Correct 1252 ms 31864 KB Output is correct
76 Correct 1262 ms 31928 KB Output is correct
77 Correct 1263 ms 31992 KB Output is correct
78 Correct 1250 ms 31928 KB Output is correct
79 Correct 1249 ms 31924 KB Output is correct
80 Correct 1243 ms 32040 KB Output is correct
81 Correct 1269 ms 31956 KB Output is correct
82 Correct 1294 ms 32044 KB Output is correct
83 Correct 1259 ms 31920 KB Output is correct
84 Correct 1267 ms 31928 KB Output is correct
85 Correct 1256 ms 31944 KB Output is correct
86 Correct 1250 ms 32120 KB Output is correct
87 Correct 1257 ms 31916 KB Output is correct
88 Correct 1259 ms 32036 KB Output is correct
89 Correct 1256 ms 32044 KB Output is correct
90 Correct 1252 ms 32104 KB Output is correct
91 Correct 1245 ms 32216 KB Output is correct
92 Correct 1249 ms 31992 KB Output is correct
93 Correct 1266 ms 32000 KB Output is correct
94 Correct 1255 ms 31992 KB Output is correct
95 Correct 1252 ms 32120 KB Output is correct
96 Correct 1245 ms 31984 KB Output is correct
97 Correct 1284 ms 31984 KB Output is correct
98 Correct 1291 ms 32100 KB Output is correct
99 Correct 1274 ms 32104 KB Output is correct
100 Correct 1138 ms 32120 KB Output is correct
101 Correct 1143 ms 31864 KB Output is correct
102 Correct 1139 ms 32120 KB Output is correct
103 Correct 1115 ms 31956 KB Output is correct
104 Correct 1133 ms 31964 KB Output is correct
105 Correct 1191 ms 31968 KB Output is correct
106 Correct 1238 ms 31964 KB Output is correct
107 Correct 1175 ms 31968 KB Output is correct
108 Correct 1182 ms 31964 KB Output is correct
109 Correct 1185 ms 31992 KB Output is correct
110 Correct 1151 ms 32120 KB Output is correct
111 Correct 1160 ms 31864 KB Output is correct
112 Correct 1160 ms 31992 KB Output is correct
113 Correct 1173 ms 32120 KB Output is correct
114 Correct 1157 ms 32092 KB Output is correct
115 Correct 1168 ms 31992 KB Output is correct
116 Correct 1162 ms 31972 KB Output is correct
117 Correct 1161 ms 31992 KB Output is correct
118 Correct 1162 ms 31996 KB Output is correct
119 Correct 1158 ms 32080 KB Output is correct
120 Correct 2 ms 504 KB Output is correct
121 Correct 2 ms 632 KB Output is correct
122 Correct 1248 ms 31996 KB Output is correct
123 Correct 1246 ms 31984 KB Output is correct
124 Correct 1247 ms 31980 KB Output is correct
125 Correct 1259 ms 32012 KB Output is correct
126 Correct 1244 ms 32120 KB Output is correct
127 Correct 1268 ms 31980 KB Output is correct
128 Correct 1248 ms 32120 KB Output is correct
129 Correct 1247 ms 32016 KB Output is correct
130 Correct 1272 ms 32008 KB Output is correct
131 Correct 1246 ms 31980 KB Output is correct
132 Correct 1255 ms 31980 KB Output is correct
133 Correct 1243 ms 31988 KB Output is correct