Submission #202900

# Submission time Handle Problem Language Result Execution time Memory
202900 2020-02-18T16:02:48 Z moonrabbit2 Bulldozer (JOI17_bulldozer) C++17
100 / 100
861 ms 47740 KB
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef tuple<int,int,int> tii;
typedef tuple<ll,ll,ll> tll;
typedef tuple<int,int,int,int> ti4;
typedef vector<vector<ll>> mat;
const ll mod=998244353,inf=1e18;
const int N=2005,M=5e7+5,K=1e5+5;
struct st{
    ll dx,dy; int idx1,idx2;
}arr[N*N]; int cnt;
int n,rev[N];
ll s1,s2,ans;
struct point{
    ll x,y,c;
}a[N];
ll mx[4*N],s[4*N],ls[4*N],rs[4*N];
void upd(int nd,int l,int r,int x,ll v){
    if(l==r){
        s[nd]=v; mx[nd]=ls[nd]=rs[nd]=max(0ll,v);
        return;
    }
    int m=(l+r)>>1;
    if(x<=m) upd(nd<<1,l,m,x,v);
    else upd(nd<<1|1,m+1,r,x,v);
    s[nd]=s[nd<<1]+s[nd<<1|1];
    mx[nd]=max({mx[nd<<1],mx[nd<<1|1],rs[nd<<1]+ls[nd<<1|1]});
    ls[nd]=max(ls[nd<<1],s[nd<<1]+ls[nd<<1|1]);
    rs[nd]=max(rs[nd<<1|1],rs[nd<<1]+s[nd<<1|1]);
}
ll ccw(pll p1,pll p2,pll p3){
    return p1.x*p2.y+p2.x*p3.y+p3.x*p1.y-p1.y*p2.x-p2.y*p3.x-p3.y*p1.x;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y>>a[i].c;
    sort(a+1,a+1+n,[](point p,point q){
        return pll(p.x,p.y)<pll(q.x,q.y);
    });
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            arr[++cnt]={a[j].x-a[i].x,a[j].y-a[i].y,i,j};
        }
    }
    sort(arr+1,arr+1+cnt,[](st p,st q){
        ll v=ccw(pll(0,0),pll(p.dx,p.dy),pll(q.dx,q.dy));
        if(v) return v>0;
        return pii(p.idx1,p.idx2)<pii(q.idx1,q.idx2);
    });
    for(int i=1;i<=n;i++){
        rev[i]=i;
        upd(1,1,n,i,a[i].c);
    }
    if(n==1) ans=mx[1];
    for(int i=1;i<=cnt;i++){
        int ii=i;
        while(ii+1<=cnt&&!ccw(pll(0,0),pll(arr[i].dx,arr[i].dy),pll(arr[ii+1].dx,arr[ii+1].dy))) ii++;
        for(int j=i;j<=ii;j++){
            int j1=arr[j].idx1,j2=arr[j].idx2;
            int k1=rev[j1],k2=rev[j2];
            swap(a[k1],a[k2]);
            swap(rev[j1],rev[j2]);
            upd(1,1,n,k1,a[k1].c);
            upd(1,1,n,k2,a[k2].c);
        }
        ans=max(ans,mx[1]);
        i=ii;
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 5 ms 500 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 508 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 408 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 6 ms 632 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 508 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 408 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 6 ms 632 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 6 ms 504 KB Output is correct
33 Correct 824 ms 47516 KB Output is correct
34 Correct 804 ms 47608 KB Output is correct
35 Correct 835 ms 47608 KB Output is correct
36 Correct 809 ms 47608 KB Output is correct
37 Correct 821 ms 47612 KB Output is correct
38 Correct 795 ms 47736 KB Output is correct
39 Correct 835 ms 47608 KB Output is correct
40 Correct 818 ms 47608 KB Output is correct
41 Correct 807 ms 47608 KB Output is correct
42 Correct 822 ms 47608 KB Output is correct
43 Correct 817 ms 47608 KB Output is correct
44 Correct 799 ms 47480 KB Output is correct
45 Correct 797 ms 47480 KB Output is correct
46 Correct 804 ms 47608 KB Output is correct
47 Correct 822 ms 47608 KB Output is correct
48 Correct 805 ms 47608 KB Output is correct
49 Correct 815 ms 47532 KB Output is correct
50 Correct 812 ms 47624 KB Output is correct
51 Correct 801 ms 47516 KB Output is correct
52 Correct 808 ms 47608 KB Output is correct
53 Correct 796 ms 47480 KB Output is correct
54 Correct 795 ms 47480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 508 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 408 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 6 ms 632 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 6 ms 504 KB Output is correct
33 Correct 824 ms 47516 KB Output is correct
34 Correct 804 ms 47608 KB Output is correct
35 Correct 835 ms 47608 KB Output is correct
36 Correct 809 ms 47608 KB Output is correct
37 Correct 821 ms 47612 KB Output is correct
38 Correct 795 ms 47736 KB Output is correct
39 Correct 835 ms 47608 KB Output is correct
40 Correct 818 ms 47608 KB Output is correct
41 Correct 807 ms 47608 KB Output is correct
42 Correct 822 ms 47608 KB Output is correct
43 Correct 817 ms 47608 KB Output is correct
44 Correct 799 ms 47480 KB Output is correct
45 Correct 797 ms 47480 KB Output is correct
46 Correct 804 ms 47608 KB Output is correct
47 Correct 822 ms 47608 KB Output is correct
48 Correct 805 ms 47608 KB Output is correct
49 Correct 815 ms 47532 KB Output is correct
50 Correct 812 ms 47624 KB Output is correct
51 Correct 801 ms 47516 KB Output is correct
52 Correct 808 ms 47608 KB Output is correct
53 Correct 796 ms 47480 KB Output is correct
54 Correct 795 ms 47480 KB Output is correct
55 Correct 812 ms 47608 KB Output is correct
56 Correct 806 ms 47672 KB Output is correct
57 Correct 806 ms 47480 KB Output is correct
58 Correct 811 ms 47480 KB Output is correct
59 Correct 807 ms 47712 KB Output is correct
60 Correct 806 ms 47608 KB Output is correct
61 Correct 821 ms 47624 KB Output is correct
62 Correct 816 ms 47608 KB Output is correct
63 Correct 817 ms 47608 KB Output is correct
64 Correct 800 ms 47740 KB Output is correct
65 Correct 833 ms 47608 KB Output is correct
66 Correct 841 ms 47528 KB Output is correct
67 Correct 861 ms 47532 KB Output is correct
68 Correct 847 ms 47544 KB Output is correct
69 Correct 841 ms 47532 KB Output is correct
70 Correct 836 ms 47536 KB Output is correct
71 Correct 853 ms 47528 KB Output is correct
72 Correct 832 ms 47608 KB Output is correct
73 Correct 846 ms 47536 KB Output is correct
74 Correct 837 ms 47608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 5 ms 500 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 508 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 408 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 380 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 6 ms 504 KB Output is correct
37 Correct 6 ms 504 KB Output is correct
38 Correct 6 ms 504 KB Output is correct
39 Correct 6 ms 504 KB Output is correct
40 Correct 6 ms 504 KB Output is correct
41 Correct 6 ms 504 KB Output is correct
42 Correct 6 ms 632 KB Output is correct
43 Correct 6 ms 504 KB Output is correct
44 Correct 6 ms 504 KB Output is correct
45 Correct 6 ms 504 KB Output is correct
46 Correct 6 ms 504 KB Output is correct
47 Correct 6 ms 504 KB Output is correct
48 Correct 824 ms 47516 KB Output is correct
49 Correct 804 ms 47608 KB Output is correct
50 Correct 835 ms 47608 KB Output is correct
51 Correct 809 ms 47608 KB Output is correct
52 Correct 821 ms 47612 KB Output is correct
53 Correct 795 ms 47736 KB Output is correct
54 Correct 835 ms 47608 KB Output is correct
55 Correct 818 ms 47608 KB Output is correct
56 Correct 807 ms 47608 KB Output is correct
57 Correct 822 ms 47608 KB Output is correct
58 Correct 817 ms 47608 KB Output is correct
59 Correct 799 ms 47480 KB Output is correct
60 Correct 797 ms 47480 KB Output is correct
61 Correct 804 ms 47608 KB Output is correct
62 Correct 822 ms 47608 KB Output is correct
63 Correct 805 ms 47608 KB Output is correct
64 Correct 815 ms 47532 KB Output is correct
65 Correct 812 ms 47624 KB Output is correct
66 Correct 801 ms 47516 KB Output is correct
67 Correct 808 ms 47608 KB Output is correct
68 Correct 796 ms 47480 KB Output is correct
69 Correct 795 ms 47480 KB Output is correct
70 Correct 812 ms 47608 KB Output is correct
71 Correct 806 ms 47672 KB Output is correct
72 Correct 806 ms 47480 KB Output is correct
73 Correct 811 ms 47480 KB Output is correct
74 Correct 807 ms 47712 KB Output is correct
75 Correct 806 ms 47608 KB Output is correct
76 Correct 821 ms 47624 KB Output is correct
77 Correct 816 ms 47608 KB Output is correct
78 Correct 817 ms 47608 KB Output is correct
79 Correct 800 ms 47740 KB Output is correct
80 Correct 833 ms 47608 KB Output is correct
81 Correct 841 ms 47528 KB Output is correct
82 Correct 861 ms 47532 KB Output is correct
83 Correct 847 ms 47544 KB Output is correct
84 Correct 841 ms 47532 KB Output is correct
85 Correct 836 ms 47536 KB Output is correct
86 Correct 853 ms 47528 KB Output is correct
87 Correct 832 ms 47608 KB Output is correct
88 Correct 846 ms 47536 KB Output is correct
89 Correct 837 ms 47608 KB Output is correct
90 Correct 845 ms 47532 KB Output is correct
91 Correct 825 ms 47480 KB Output is correct
92 Correct 839 ms 47520 KB Output is correct
93 Correct 841 ms 47516 KB Output is correct
94 Correct 821 ms 47536 KB Output is correct
95 Correct 821 ms 47608 KB Output is correct
96 Correct 834 ms 47532 KB Output is correct
97 Correct 854 ms 47548 KB Output is correct
98 Correct 805 ms 47608 KB Output is correct
99 Correct 811 ms 47608 KB Output is correct
100 Correct 650 ms 47612 KB Output is correct
101 Correct 625 ms 47480 KB Output is correct
102 Correct 648 ms 47480 KB Output is correct
103 Correct 677 ms 47528 KB Output is correct
104 Correct 649 ms 47480 KB Output is correct
105 Correct 694 ms 47612 KB Output is correct
106 Correct 681 ms 47480 KB Output is correct
107 Correct 677 ms 47480 KB Output is correct
108 Correct 679 ms 47608 KB Output is correct
109 Correct 677 ms 47576 KB Output is correct
110 Correct 735 ms 47480 KB Output is correct
111 Correct 771 ms 47680 KB Output is correct
112 Correct 756 ms 47480 KB Output is correct
113 Correct 742 ms 47736 KB Output is correct
114 Correct 750 ms 47608 KB Output is correct
115 Correct 769 ms 47568 KB Output is correct
116 Correct 766 ms 47584 KB Output is correct
117 Correct 741 ms 47608 KB Output is correct
118 Correct 744 ms 47480 KB Output is correct
119 Correct 745 ms 47608 KB Output is correct
120 Correct 5 ms 376 KB Output is correct
121 Correct 5 ms 376 KB Output is correct
122 Correct 813 ms 47608 KB Output is correct
123 Correct 831 ms 47484 KB Output is correct
124 Correct 824 ms 47704 KB Output is correct
125 Correct 804 ms 47608 KB Output is correct
126 Correct 815 ms 47480 KB Output is correct
127 Correct 823 ms 47480 KB Output is correct
128 Correct 808 ms 47596 KB Output is correct
129 Correct 803 ms 47480 KB Output is correct
130 Correct 808 ms 47608 KB Output is correct
131 Correct 813 ms 47608 KB Output is correct
132 Correct 810 ms 47608 KB Output is correct
133 Correct 800 ms 47608 KB Output is correct