답안 #135555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135555 2019-07-24T08:13:02 Z ksmzzang2003 Bulldozer (JOI17_bulldozer) C++14
100 / 100
668 ms 33488 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*b.dx*a.dy;
}

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[2*x],tree[2*x+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:86:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();)
                 ~^~~~~~~~~
bulldozer.cpp:89:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(e < v.size() && ccw(v[i],v[e]) == 0) e++;
               ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 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 504 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 604 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 508 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 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 376 KB Output is correct
19 Correct 2 ms 376 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 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 508 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 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 504 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 604 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 508 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 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 376 KB Output is correct
19 Correct 2 ms 376 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 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 508 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 644 ms 33408 KB Output is correct
34 Correct 635 ms 33344 KB Output is correct
35 Correct 637 ms 33340 KB Output is correct
36 Correct 646 ms 33340 KB Output is correct
37 Correct 631 ms 33468 KB Output is correct
38 Correct 624 ms 33340 KB Output is correct
39 Correct 628 ms 33344 KB Output is correct
40 Correct 635 ms 33480 KB Output is correct
41 Correct 628 ms 33340 KB Output is correct
42 Correct 632 ms 33340 KB Output is correct
43 Correct 634 ms 33468 KB Output is correct
44 Correct 624 ms 33440 KB Output is correct
45 Correct 620 ms 33340 KB Output is correct
46 Correct 624 ms 33340 KB Output is correct
47 Correct 621 ms 33340 KB Output is correct
48 Correct 625 ms 33468 KB Output is correct
49 Correct 626 ms 33468 KB Output is correct
50 Correct 630 ms 33340 KB Output is correct
51 Correct 634 ms 33344 KB Output is correct
52 Correct 653 ms 33340 KB Output is correct
53 Correct 626 ms 33340 KB Output is correct
54 Correct 625 ms 33472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 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 504 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 604 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 508 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 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 376 KB Output is correct
19 Correct 2 ms 376 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 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 508 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 644 ms 33408 KB Output is correct
34 Correct 635 ms 33344 KB Output is correct
35 Correct 637 ms 33340 KB Output is correct
36 Correct 646 ms 33340 KB Output is correct
37 Correct 631 ms 33468 KB Output is correct
38 Correct 624 ms 33340 KB Output is correct
39 Correct 628 ms 33344 KB Output is correct
40 Correct 635 ms 33480 KB Output is correct
41 Correct 628 ms 33340 KB Output is correct
42 Correct 632 ms 33340 KB Output is correct
43 Correct 634 ms 33468 KB Output is correct
44 Correct 624 ms 33440 KB Output is correct
45 Correct 620 ms 33340 KB Output is correct
46 Correct 624 ms 33340 KB Output is correct
47 Correct 621 ms 33340 KB Output is correct
48 Correct 625 ms 33468 KB Output is correct
49 Correct 626 ms 33468 KB Output is correct
50 Correct 630 ms 33340 KB Output is correct
51 Correct 634 ms 33344 KB Output is correct
52 Correct 653 ms 33340 KB Output is correct
53 Correct 626 ms 33340 KB Output is correct
54 Correct 625 ms 33472 KB Output is correct
55 Correct 654 ms 33380 KB Output is correct
56 Correct 634 ms 33340 KB Output is correct
57 Correct 633 ms 33480 KB Output is correct
58 Correct 638 ms 33340 KB Output is correct
59 Correct 638 ms 33340 KB Output is correct
60 Correct 633 ms 33340 KB Output is correct
61 Correct 632 ms 33468 KB Output is correct
62 Correct 636 ms 33316 KB Output is correct
63 Correct 641 ms 33380 KB Output is correct
64 Correct 635 ms 33376 KB Output is correct
65 Correct 628 ms 33468 KB Output is correct
66 Correct 635 ms 33488 KB Output is correct
67 Correct 628 ms 33340 KB Output is correct
68 Correct 634 ms 33468 KB Output is correct
69 Correct 668 ms 33340 KB Output is correct
70 Correct 661 ms 33468 KB Output is correct
71 Correct 649 ms 33468 KB Output is correct
72 Correct 631 ms 33468 KB Output is correct
73 Correct 642 ms 33340 KB Output is correct
74 Correct 642 ms 33340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 376 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 504 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 508 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 256 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 376 KB Output is correct
34 Correct 2 ms 376 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 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 508 KB Output is correct
43 Correct 3 ms 632 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 3 ms 632 KB Output is correct
46 Correct 3 ms 632 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 644 ms 33408 KB Output is correct
49 Correct 635 ms 33344 KB Output is correct
50 Correct 637 ms 33340 KB Output is correct
51 Correct 646 ms 33340 KB Output is correct
52 Correct 631 ms 33468 KB Output is correct
53 Correct 624 ms 33340 KB Output is correct
54 Correct 628 ms 33344 KB Output is correct
55 Correct 635 ms 33480 KB Output is correct
56 Correct 628 ms 33340 KB Output is correct
57 Correct 632 ms 33340 KB Output is correct
58 Correct 634 ms 33468 KB Output is correct
59 Correct 624 ms 33440 KB Output is correct
60 Correct 620 ms 33340 KB Output is correct
61 Correct 624 ms 33340 KB Output is correct
62 Correct 621 ms 33340 KB Output is correct
63 Correct 625 ms 33468 KB Output is correct
64 Correct 626 ms 33468 KB Output is correct
65 Correct 630 ms 33340 KB Output is correct
66 Correct 634 ms 33344 KB Output is correct
67 Correct 653 ms 33340 KB Output is correct
68 Correct 626 ms 33340 KB Output is correct
69 Correct 625 ms 33472 KB Output is correct
70 Correct 654 ms 33380 KB Output is correct
71 Correct 634 ms 33340 KB Output is correct
72 Correct 633 ms 33480 KB Output is correct
73 Correct 638 ms 33340 KB Output is correct
74 Correct 638 ms 33340 KB Output is correct
75 Correct 633 ms 33340 KB Output is correct
76 Correct 632 ms 33468 KB Output is correct
77 Correct 636 ms 33316 KB Output is correct
78 Correct 641 ms 33380 KB Output is correct
79 Correct 635 ms 33376 KB Output is correct
80 Correct 628 ms 33468 KB Output is correct
81 Correct 635 ms 33488 KB Output is correct
82 Correct 628 ms 33340 KB Output is correct
83 Correct 634 ms 33468 KB Output is correct
84 Correct 668 ms 33340 KB Output is correct
85 Correct 661 ms 33468 KB Output is correct
86 Correct 649 ms 33468 KB Output is correct
87 Correct 631 ms 33468 KB Output is correct
88 Correct 642 ms 33340 KB Output is correct
89 Correct 642 ms 33340 KB Output is correct
90 Correct 653 ms 33340 KB Output is correct
91 Correct 638 ms 33472 KB Output is correct
92 Correct 639 ms 33372 KB Output is correct
93 Correct 636 ms 33468 KB Output is correct
94 Correct 650 ms 33472 KB Output is correct
95 Correct 630 ms 33440 KB Output is correct
96 Correct 628 ms 33468 KB Output is correct
97 Correct 636 ms 33468 KB Output is correct
98 Correct 625 ms 33468 KB Output is correct
99 Correct 631 ms 33468 KB Output is correct
100 Correct 516 ms 33340 KB Output is correct
101 Correct 512 ms 33380 KB Output is correct
102 Correct 519 ms 33348 KB Output is correct
103 Correct 513 ms 33340 KB Output is correct
104 Correct 516 ms 33468 KB Output is correct
105 Correct 550 ms 33340 KB Output is correct
106 Correct 544 ms 33340 KB Output is correct
107 Correct 552 ms 33344 KB Output is correct
108 Correct 532 ms 33468 KB Output is correct
109 Correct 535 ms 33340 KB Output is correct
110 Correct 618 ms 33468 KB Output is correct
111 Correct 618 ms 33424 KB Output is correct
112 Correct 617 ms 33340 KB Output is correct
113 Correct 615 ms 33340 KB Output is correct
114 Correct 638 ms 33344 KB Output is correct
115 Correct 620 ms 33340 KB Output is correct
116 Correct 653 ms 33340 KB Output is correct
117 Correct 620 ms 33340 KB Output is correct
118 Correct 621 ms 33340 KB Output is correct
119 Correct 621 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 633 ms 33468 KB Output is correct
123 Correct 637 ms 33468 KB Output is correct
124 Correct 639 ms 33468 KB Output is correct
125 Correct 633 ms 33468 KB Output is correct
126 Correct 632 ms 33468 KB Output is correct
127 Correct 635 ms 33336 KB Output is correct
128 Correct 640 ms 33340 KB Output is correct
129 Correct 645 ms 33372 KB Output is correct
130 Correct 629 ms 33340 KB Output is correct
131 Correct 637 ms 33348 KB Output is correct
132 Correct 662 ms 33440 KB Output is correct
133 Correct 645 ms 33468 KB Output is correct