Submission #136540

# Submission time Handle Problem Language Result Execution time Memory
136540 2019-07-25T12:52:03 Z ksmzzang2003 Bulldozer (JOI17_bulldozer) C++17
100 / 100
681 ms 33544 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;

struct sweep {
    int dx,dy,idx1,idx2;
    bool operator <(const sweep &r) const {
        ll k = 1ll*dx*r.dy - 1ll*dy*r.dx;
        return (k!=0)?(k>0) : (pii(idx1,idx2) < pii(r.idx1,r.idx2));
    }
};

ll ccw(sweep a,sweep b) {
    return 1ll*a.dx*b.dy - 1ll* a.dy * b.dx;
}

struct point {
    int x,y,c;
    bool operator <(const point &r)const {
        return pii(x,y)<pii(r.x,r.y);
    }
} arr[2005];

struct seg {
    struct node {
        ll sum,lsum,rsum,opt;
    } tree[4100];
    int lim;
    node make(int x) {
        return (node) {
            x,max(x,0),max(x,0),max(x,0)
        };
    }
    node merge(node l,node r) {
        return (node) {
            l.sum+r.sum,max(l.lsum,l.sum+r.lsum),max(r.rsum,r.sum+l.rsum),max({l.opt,r.opt,l.rsum+r.lsum})
        };
    }
    void init(int n,point *arr) {
        for(lim=1; lim<=n; lim<<=1);
        for(int j=0; j<n; j++)
            tree[j+lim] = make(arr[j].c);
        for(int j=lim-1; j>=1; j--)
            tree[j] = merge(tree[j*2],tree[j*2+1]);
    }
    void update(int x,int v) {
        x+=lim;
        tree[x] = make(v);
        while(x>1) {
            x>>=1;
            tree[x] = merge(tree[x*2],tree[x*2+1]);
        }
    }
    ll query() {
        return tree[1].opt;
    }
} seg;

int n,rev[2005];
vector <sweep> v;

int main() {
    cin>>n ;
    for(int i=0; i<n; i++)
        cin>>arr[i].x>>arr[i].y>>arr[i].c;
    if(n==1)
        return !printf("%d",max(0,arr[0].c));
    sort(arr,arr+n);
    iota(rev,rev+n,0);
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
            v.push_back({arr[j].x-arr[i].x,arr[j].y-arr[i].y,i,j});
    sort(v.begin(),v.end());
    seg.init(n,arr);
    ll ans =0;
    for(int i=0; i<v.size();) {
        int e=i;
        while(e<v.size() && ccw(v[i],v[e])==0)
            e++;
        for(int j=i; j<e; j++) {
            int rx = rev[v[j].idx1],ry=rev[v[j].idx2];
            swap(rev[v[j].idx1],rev[v[j].idx2]);
            swap(arr[rx],arr[ry]);
            seg.update(rx,arr[rx].c);
            seg.update(ry,arr[ry].c);
        }
        ans = max(ans,seg.query());
        i=e;
    }
    cout<<ans;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<v.size();) {
                  ~^~~~~~~~~
bulldozer.cpp:79:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(e<v.size() && ccw(v[i],v[e])==0)
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 660 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 360 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 252 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 4 ms 548 KB Output is correct
24 Correct 4 ms 636 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 252 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 4 ms 548 KB Output is correct
24 Correct 4 ms 636 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 640 ms 33356 KB Output is correct
34 Correct 632 ms 33472 KB Output is correct
35 Correct 656 ms 33468 KB Output is correct
36 Correct 640 ms 33340 KB Output is correct
37 Correct 681 ms 33340 KB Output is correct
38 Correct 637 ms 33340 KB Output is correct
39 Correct 636 ms 33468 KB Output is correct
40 Correct 641 ms 33472 KB Output is correct
41 Correct 634 ms 33468 KB Output is correct
42 Correct 636 ms 33468 KB Output is correct
43 Correct 636 ms 33340 KB Output is correct
44 Correct 621 ms 33468 KB Output is correct
45 Correct 627 ms 33344 KB Output is correct
46 Correct 626 ms 33340 KB Output is correct
47 Correct 621 ms 33508 KB Output is correct
48 Correct 645 ms 33468 KB Output is correct
49 Correct 659 ms 33340 KB Output is correct
50 Correct 626 ms 33340 KB Output is correct
51 Correct 623 ms 33340 KB Output is correct
52 Correct 624 ms 33340 KB Output is correct
53 Correct 622 ms 33512 KB Output is correct
54 Correct 625 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 252 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 4 ms 548 KB Output is correct
24 Correct 4 ms 636 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 640 ms 33356 KB Output is correct
34 Correct 632 ms 33472 KB Output is correct
35 Correct 656 ms 33468 KB Output is correct
36 Correct 640 ms 33340 KB Output is correct
37 Correct 681 ms 33340 KB Output is correct
38 Correct 637 ms 33340 KB Output is correct
39 Correct 636 ms 33468 KB Output is correct
40 Correct 641 ms 33472 KB Output is correct
41 Correct 634 ms 33468 KB Output is correct
42 Correct 636 ms 33468 KB Output is correct
43 Correct 636 ms 33340 KB Output is correct
44 Correct 621 ms 33468 KB Output is correct
45 Correct 627 ms 33344 KB Output is correct
46 Correct 626 ms 33340 KB Output is correct
47 Correct 621 ms 33508 KB Output is correct
48 Correct 645 ms 33468 KB Output is correct
49 Correct 659 ms 33340 KB Output is correct
50 Correct 626 ms 33340 KB Output is correct
51 Correct 623 ms 33340 KB Output is correct
52 Correct 624 ms 33340 KB Output is correct
53 Correct 622 ms 33512 KB Output is correct
54 Correct 625 ms 33340 KB Output is correct
55 Correct 628 ms 33400 KB Output is correct
56 Correct 628 ms 33340 KB Output is correct
57 Correct 634 ms 33468 KB Output is correct
58 Correct 633 ms 33340 KB Output is correct
59 Correct 637 ms 33468 KB Output is correct
60 Correct 634 ms 33468 KB Output is correct
61 Correct 632 ms 33344 KB Output is correct
62 Correct 633 ms 33340 KB Output is correct
63 Correct 648 ms 33468 KB Output is correct
64 Correct 651 ms 33468 KB Output is correct
65 Correct 629 ms 33468 KB Output is correct
66 Correct 629 ms 33340 KB Output is correct
67 Correct 632 ms 33340 KB Output is correct
68 Correct 641 ms 33472 KB Output is correct
69 Correct 642 ms 33340 KB Output is correct
70 Correct 648 ms 33544 KB Output is correct
71 Correct 628 ms 33468 KB Output is correct
72 Correct 636 ms 33468 KB Output is correct
73 Correct 634 ms 33468 KB Output is correct
74 Correct 633 ms 33468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 660 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 360 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 2 ms 252 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 252 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 632 KB Output is correct
38 Correct 4 ms 548 KB Output is correct
39 Correct 4 ms 636 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 632 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 4 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 640 ms 33356 KB Output is correct
49 Correct 632 ms 33472 KB Output is correct
50 Correct 656 ms 33468 KB Output is correct
51 Correct 640 ms 33340 KB Output is correct
52 Correct 681 ms 33340 KB Output is correct
53 Correct 637 ms 33340 KB Output is correct
54 Correct 636 ms 33468 KB Output is correct
55 Correct 641 ms 33472 KB Output is correct
56 Correct 634 ms 33468 KB Output is correct
57 Correct 636 ms 33468 KB Output is correct
58 Correct 636 ms 33340 KB Output is correct
59 Correct 621 ms 33468 KB Output is correct
60 Correct 627 ms 33344 KB Output is correct
61 Correct 626 ms 33340 KB Output is correct
62 Correct 621 ms 33508 KB Output is correct
63 Correct 645 ms 33468 KB Output is correct
64 Correct 659 ms 33340 KB Output is correct
65 Correct 626 ms 33340 KB Output is correct
66 Correct 623 ms 33340 KB Output is correct
67 Correct 624 ms 33340 KB Output is correct
68 Correct 622 ms 33512 KB Output is correct
69 Correct 625 ms 33340 KB Output is correct
70 Correct 628 ms 33400 KB Output is correct
71 Correct 628 ms 33340 KB Output is correct
72 Correct 634 ms 33468 KB Output is correct
73 Correct 633 ms 33340 KB Output is correct
74 Correct 637 ms 33468 KB Output is correct
75 Correct 634 ms 33468 KB Output is correct
76 Correct 632 ms 33344 KB Output is correct
77 Correct 633 ms 33340 KB Output is correct
78 Correct 648 ms 33468 KB Output is correct
79 Correct 651 ms 33468 KB Output is correct
80 Correct 629 ms 33468 KB Output is correct
81 Correct 629 ms 33340 KB Output is correct
82 Correct 632 ms 33340 KB Output is correct
83 Correct 641 ms 33472 KB Output is correct
84 Correct 642 ms 33340 KB Output is correct
85 Correct 648 ms 33544 KB Output is correct
86 Correct 628 ms 33468 KB Output is correct
87 Correct 636 ms 33468 KB Output is correct
88 Correct 634 ms 33468 KB Output is correct
89 Correct 633 ms 33468 KB Output is correct
90 Correct 638 ms 33340 KB Output is correct
91 Correct 628 ms 33340 KB Output is correct
92 Correct 642 ms 33468 KB Output is correct
93 Correct 635 ms 33468 KB Output is correct
94 Correct 629 ms 33468 KB Output is correct
95 Correct 627 ms 33472 KB Output is correct
96 Correct 630 ms 33440 KB Output is correct
97 Correct 633 ms 33476 KB Output is correct
98 Correct 627 ms 33468 KB Output is correct
99 Correct 631 ms 33468 KB Output is correct
100 Correct 512 ms 33340 KB Output is correct
101 Correct 511 ms 33340 KB Output is correct
102 Correct 512 ms 33468 KB Output is correct
103 Correct 521 ms 33344 KB Output is correct
104 Correct 514 ms 33340 KB Output is correct
105 Correct 548 ms 33340 KB Output is correct
106 Correct 539 ms 33340 KB Output is correct
107 Correct 534 ms 33340 KB Output is correct
108 Correct 536 ms 33340 KB Output is correct
109 Correct 532 ms 33340 KB Output is correct
110 Correct 615 ms 33340 KB Output is correct
111 Correct 627 ms 33340 KB Output is correct
112 Correct 619 ms 33340 KB Output is correct
113 Correct 616 ms 33468 KB Output is correct
114 Correct 623 ms 33340 KB Output is correct
115 Correct 625 ms 33340 KB Output is correct
116 Correct 636 ms 33340 KB Output is correct
117 Correct 620 ms 33340 KB Output is correct
118 Correct 614 ms 33340 KB Output is correct
119 Correct 619 ms 33468 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 639 ms 33468 KB Output is correct
123 Correct 633 ms 33468 KB Output is correct
124 Correct 646 ms 33468 KB Output is correct
125 Correct 635 ms 33340 KB Output is correct
126 Correct 630 ms 33340 KB Output is correct
127 Correct 634 ms 33336 KB Output is correct
128 Correct 626 ms 33340 KB Output is correct
129 Correct 632 ms 33468 KB Output is correct
130 Correct 644 ms 33468 KB Output is correct
131 Correct 643 ms 33340 KB Output is correct
132 Correct 645 ms 33468 KB Output is correct
133 Correct 626 ms 33440 KB Output is correct