답안 #134313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134313 2019-07-22T12:07:48 Z ksmzzang2003 Bulldozer (JOI17_bulldozer) C++17
100 / 100
688 ms 33608 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;

struct sweep
{
    int dx,dy,idx1,idx2;
    int mode()
    {
        return pii(dx,dy)<pii(0,0);
    }
    bool operator <(const sweep &r) const
    {
        ll k = 1ll*dx*r.dy - 1ll*dy*r.dx; // cross (dx,dy) (s.dx,s.dy)
        if(k!=0)
            return k>0;
        else if(k==0)
            return 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)
    {
        node ret ;
        ret.sum = l.sum + r.sum;
        ret.lsum = max(l.lsum,l.sum+r.lsum);
        ret.rsum = max(r.rsum,r.sum+l.rsum);
        ret.opt = max({l.opt,r.opt,l.rsum+r.lsum}) ;
        return ret;
    }
    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)
    {
        cout << max(0,arr[0].c);
        return 0;
    }
    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:105:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();)
                 ~^~~~~~~~~
bulldozer.cpp:108:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(e < v.size() && ccw(v[i],v[e]) == 0) e++;
               ~~^~~~~~~~~~
bulldozer.cpp: In member function 'bool sweep::operator<(const sweep&) const':
bulldozer.cpp:20:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 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 544 KB Output is correct
5 Correct 3 ms 632 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 632 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 380 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 636 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 504 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 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 504 KB Output is correct
10 Correct 4 ms 632 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 2 ms 252 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 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 632 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 504 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 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 636 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 504 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 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 504 KB Output is correct
10 Correct 4 ms 632 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 2 ms 252 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 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 632 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 504 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 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 688 ms 33340 KB Output is correct
34 Correct 626 ms 33468 KB Output is correct
35 Correct 639 ms 33340 KB Output is correct
36 Correct 626 ms 33472 KB Output is correct
37 Correct 628 ms 33468 KB Output is correct
38 Correct 649 ms 33472 KB Output is correct
39 Correct 641 ms 33468 KB Output is correct
40 Correct 632 ms 33468 KB Output is correct
41 Correct 627 ms 33340 KB Output is correct
42 Correct 630 ms 33468 KB Output is correct
43 Correct 625 ms 33468 KB Output is correct
44 Correct 619 ms 33468 KB Output is correct
45 Correct 624 ms 33340 KB Output is correct
46 Correct 623 ms 33340 KB Output is correct
47 Correct 625 ms 33608 KB Output is correct
48 Correct 625 ms 33340 KB Output is correct
49 Correct 636 ms 33468 KB Output is correct
50 Correct 621 ms 33472 KB Output is correct
51 Correct 627 ms 33468 KB Output is correct
52 Correct 621 ms 33468 KB Output is correct
53 Correct 626 ms 33468 KB Output is correct
54 Correct 621 ms 33340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 636 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 504 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 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 504 KB Output is correct
10 Correct 4 ms 632 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 2 ms 252 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 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 632 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 504 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 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 688 ms 33340 KB Output is correct
34 Correct 626 ms 33468 KB Output is correct
35 Correct 639 ms 33340 KB Output is correct
36 Correct 626 ms 33472 KB Output is correct
37 Correct 628 ms 33468 KB Output is correct
38 Correct 649 ms 33472 KB Output is correct
39 Correct 641 ms 33468 KB Output is correct
40 Correct 632 ms 33468 KB Output is correct
41 Correct 627 ms 33340 KB Output is correct
42 Correct 630 ms 33468 KB Output is correct
43 Correct 625 ms 33468 KB Output is correct
44 Correct 619 ms 33468 KB Output is correct
45 Correct 624 ms 33340 KB Output is correct
46 Correct 623 ms 33340 KB Output is correct
47 Correct 625 ms 33608 KB Output is correct
48 Correct 625 ms 33340 KB Output is correct
49 Correct 636 ms 33468 KB Output is correct
50 Correct 621 ms 33472 KB Output is correct
51 Correct 627 ms 33468 KB Output is correct
52 Correct 621 ms 33468 KB Output is correct
53 Correct 626 ms 33468 KB Output is correct
54 Correct 621 ms 33340 KB Output is correct
55 Correct 637 ms 33392 KB Output is correct
56 Correct 627 ms 33468 KB Output is correct
57 Correct 635 ms 33468 KB Output is correct
58 Correct 629 ms 33344 KB Output is correct
59 Correct 631 ms 33468 KB Output is correct
60 Correct 631 ms 33340 KB Output is correct
61 Correct 627 ms 33468 KB Output is correct
62 Correct 631 ms 33340 KB Output is correct
63 Correct 629 ms 33340 KB Output is correct
64 Correct 629 ms 33340 KB Output is correct
65 Correct 631 ms 33340 KB Output is correct
66 Correct 645 ms 33468 KB Output is correct
67 Correct 624 ms 33468 KB Output is correct
68 Correct 684 ms 33340 KB Output is correct
69 Correct 635 ms 33344 KB Output is correct
70 Correct 636 ms 33472 KB Output is correct
71 Correct 630 ms 33340 KB Output is correct
72 Correct 631 ms 33344 KB Output is correct
73 Correct 630 ms 33472 KB Output is correct
74 Correct 630 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 632 KB Output is correct
4 Correct 3 ms 544 KB Output is correct
5 Correct 3 ms 632 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 632 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 380 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 636 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 504 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 3 ms 632 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 504 KB Output is correct
25 Correct 4 ms 632 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 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 252 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 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 632 KB Output is correct
37 Correct 3 ms 632 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 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 632 KB Output is correct
47 Correct 3 ms 632 KB Output is correct
48 Correct 688 ms 33340 KB Output is correct
49 Correct 626 ms 33468 KB Output is correct
50 Correct 639 ms 33340 KB Output is correct
51 Correct 626 ms 33472 KB Output is correct
52 Correct 628 ms 33468 KB Output is correct
53 Correct 649 ms 33472 KB Output is correct
54 Correct 641 ms 33468 KB Output is correct
55 Correct 632 ms 33468 KB Output is correct
56 Correct 627 ms 33340 KB Output is correct
57 Correct 630 ms 33468 KB Output is correct
58 Correct 625 ms 33468 KB Output is correct
59 Correct 619 ms 33468 KB Output is correct
60 Correct 624 ms 33340 KB Output is correct
61 Correct 623 ms 33340 KB Output is correct
62 Correct 625 ms 33608 KB Output is correct
63 Correct 625 ms 33340 KB Output is correct
64 Correct 636 ms 33468 KB Output is correct
65 Correct 621 ms 33472 KB Output is correct
66 Correct 627 ms 33468 KB Output is correct
67 Correct 621 ms 33468 KB Output is correct
68 Correct 626 ms 33468 KB Output is correct
69 Correct 621 ms 33340 KB Output is correct
70 Correct 637 ms 33392 KB Output is correct
71 Correct 627 ms 33468 KB Output is correct
72 Correct 635 ms 33468 KB Output is correct
73 Correct 629 ms 33344 KB Output is correct
74 Correct 631 ms 33468 KB Output is correct
75 Correct 631 ms 33340 KB Output is correct
76 Correct 627 ms 33468 KB Output is correct
77 Correct 631 ms 33340 KB Output is correct
78 Correct 629 ms 33340 KB Output is correct
79 Correct 629 ms 33340 KB Output is correct
80 Correct 631 ms 33340 KB Output is correct
81 Correct 645 ms 33468 KB Output is correct
82 Correct 624 ms 33468 KB Output is correct
83 Correct 684 ms 33340 KB Output is correct
84 Correct 635 ms 33344 KB Output is correct
85 Correct 636 ms 33472 KB Output is correct
86 Correct 630 ms 33340 KB Output is correct
87 Correct 631 ms 33344 KB Output is correct
88 Correct 630 ms 33472 KB Output is correct
89 Correct 630 ms 33340 KB Output is correct
90 Correct 634 ms 33452 KB Output is correct
91 Correct 628 ms 33468 KB Output is correct
92 Correct 630 ms 33340 KB Output is correct
93 Correct 636 ms 33468 KB Output is correct
94 Correct 647 ms 33472 KB Output is correct
95 Correct 630 ms 33468 KB Output is correct
96 Correct 634 ms 33468 KB Output is correct
97 Correct 634 ms 33344 KB Output is correct
98 Correct 627 ms 33468 KB Output is correct
99 Correct 638 ms 33340 KB Output is correct
100 Correct 507 ms 33340 KB Output is correct
101 Correct 506 ms 33340 KB Output is correct
102 Correct 511 ms 33336 KB Output is correct
103 Correct 516 ms 33340 KB Output is correct
104 Correct 509 ms 33340 KB Output is correct
105 Correct 550 ms 33468 KB Output is correct
106 Correct 546 ms 33340 KB Output is correct
107 Correct 528 ms 33468 KB Output is correct
108 Correct 529 ms 33340 KB Output is correct
109 Correct 532 ms 33520 KB Output is correct
110 Correct 612 ms 33340 KB Output is correct
111 Correct 614 ms 33468 KB Output is correct
112 Correct 619 ms 33340 KB Output is correct
113 Correct 632 ms 33340 KB Output is correct
114 Correct 619 ms 33340 KB Output is correct
115 Correct 617 ms 33340 KB Output is correct
116 Correct 636 ms 33344 KB Output is correct
117 Correct 622 ms 33468 KB Output is correct
118 Correct 615 ms 33340 KB Output is correct
119 Correct 614 ms 33340 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 632 ms 33468 KB Output is correct
123 Correct 630 ms 33468 KB Output is correct
124 Correct 634 ms 33340 KB Output is correct
125 Correct 631 ms 33468 KB Output is correct
126 Correct 624 ms 33340 KB Output is correct
127 Correct 628 ms 33468 KB Output is correct
128 Correct 627 ms 33496 KB Output is correct
129 Correct 623 ms 33340 KB Output is correct
130 Correct 623 ms 33472 KB Output is correct
131 Correct 662 ms 33468 KB Output is correct
132 Correct 633 ms 33468 KB Output is correct
133 Correct 631 ms 33340 KB Output is correct