Submission #156374

# Submission time Handle Problem Language Result Execution time Memory
156374 2019-10-05T11:37:10 Z georgerapeanu Bulldozer (JOI17_bulldozer) C++11
75 / 100
1249 ms 32120 KB
#include <cstdio>
#include <algorithm>

using namespace std;

struct point_t{
    int x,y,c;

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

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;
int ord[2005];
point_t v[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){return 1LL * a.b * b.a < 1LL * b.b * a.a;});

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

    build(1,1,n);

    long long ans = aint[1].best_sum;

    for(int i = 1;i <= len;i++){
        swap(ord[lines[i].i],ord[lines[i].j]);
        update(1,1,n,ord[lines[i].i],v[lines[i].i].c);
        update(1,1,n,ord[lines[i].j],v[lines[i].j].c);
        if(i == n || (1LL * lines[i].b * lines[i + 1].a < 1LL * lines[i + 1].b * lines[i].a)){
            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 3 ms 632 KB Output is correct
2 Incorrect 4 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 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 632 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 504 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 632 KB Output is correct
20 Correct 2 ms 632 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 4 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 632 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 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 632 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 504 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 632 KB Output is correct
20 Correct 2 ms 632 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 4 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 632 KB Output is correct
33 Correct 1236 ms 32112 KB Output is correct
34 Correct 1205 ms 31980 KB Output is correct
35 Correct 1205 ms 31980 KB Output is correct
36 Correct 1203 ms 31988 KB Output is correct
37 Correct 1224 ms 31992 KB Output is correct
38 Correct 1208 ms 31996 KB Output is correct
39 Correct 1211 ms 31992 KB Output is correct
40 Correct 1222 ms 32100 KB Output is correct
41 Correct 1218 ms 31988 KB Output is correct
42 Correct 1209 ms 31992 KB Output is correct
43 Correct 1212 ms 32104 KB Output is correct
44 Correct 1199 ms 32108 KB Output is correct
45 Correct 1205 ms 31984 KB Output is correct
46 Correct 1231 ms 32016 KB Output is correct
47 Correct 1206 ms 32120 KB Output is correct
48 Correct 1204 ms 31988 KB Output is correct
49 Correct 1201 ms 32116 KB Output is correct
50 Correct 1202 ms 31984 KB Output is correct
51 Correct 1202 ms 31864 KB Output is correct
52 Correct 1207 ms 31864 KB Output is correct
53 Correct 1196 ms 32120 KB Output is correct
54 Correct 1199 ms 32120 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 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 632 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 504 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 632 KB Output is correct
20 Correct 2 ms 632 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 4 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 632 KB Output is correct
33 Correct 1236 ms 32112 KB Output is correct
34 Correct 1205 ms 31980 KB Output is correct
35 Correct 1205 ms 31980 KB Output is correct
36 Correct 1203 ms 31988 KB Output is correct
37 Correct 1224 ms 31992 KB Output is correct
38 Correct 1208 ms 31996 KB Output is correct
39 Correct 1211 ms 31992 KB Output is correct
40 Correct 1222 ms 32100 KB Output is correct
41 Correct 1218 ms 31988 KB Output is correct
42 Correct 1209 ms 31992 KB Output is correct
43 Correct 1212 ms 32104 KB Output is correct
44 Correct 1199 ms 32108 KB Output is correct
45 Correct 1205 ms 31984 KB Output is correct
46 Correct 1231 ms 32016 KB Output is correct
47 Correct 1206 ms 32120 KB Output is correct
48 Correct 1204 ms 31988 KB Output is correct
49 Correct 1201 ms 32116 KB Output is correct
50 Correct 1202 ms 31984 KB Output is correct
51 Correct 1202 ms 31864 KB Output is correct
52 Correct 1207 ms 31864 KB Output is correct
53 Correct 1196 ms 32120 KB Output is correct
54 Correct 1199 ms 32120 KB Output is correct
55 Correct 1214 ms 31984 KB Output is correct
56 Correct 1204 ms 31992 KB Output is correct
57 Correct 1214 ms 31992 KB Output is correct
58 Correct 1215 ms 31996 KB Output is correct
59 Correct 1213 ms 32012 KB Output is correct
60 Correct 1215 ms 32112 KB Output is correct
61 Correct 1222 ms 32020 KB Output is correct
62 Correct 1249 ms 31992 KB Output is correct
63 Correct 1236 ms 32104 KB Output is correct
64 Correct 1217 ms 31980 KB Output is correct
65 Correct 1208 ms 32120 KB Output is correct
66 Correct 1209 ms 32120 KB Output is correct
67 Correct 1207 ms 31996 KB Output is correct
68 Correct 1215 ms 31992 KB Output is correct
69 Correct 1211 ms 31972 KB Output is correct
70 Correct 1214 ms 31984 KB Output is correct
71 Correct 1213 ms 32108 KB Output is correct
72 Correct 1232 ms 31984 KB Output is correct
73 Correct 1249 ms 31984 KB Output is correct
74 Correct 1209 ms 32112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Incorrect 4 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -