답안 #202899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202899 2020-02-18T16:00:41 Z moonrabbit2 Bulldozer (JOI17_bulldozer) C++17
100 / 100
878 ms 47736 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);
    }
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 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 5 ms 508 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 6 ms 632 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 376 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
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 7 ms 508 KB Output is correct
4 Correct 6 ms 504 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 376 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 416 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 508 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
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 7 ms 508 KB Output is correct
4 Correct 6 ms 504 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 376 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 416 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 508 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 827 ms 47608 KB Output is correct
34 Correct 819 ms 47608 KB Output is correct
35 Correct 809 ms 47480 KB Output is correct
36 Correct 804 ms 47480 KB Output is correct
37 Correct 813 ms 47600 KB Output is correct
38 Correct 813 ms 47608 KB Output is correct
39 Correct 801 ms 47608 KB Output is correct
40 Correct 814 ms 47608 KB Output is correct
41 Correct 838 ms 47608 KB Output is correct
42 Correct 799 ms 47608 KB Output is correct
43 Correct 808 ms 47584 KB Output is correct
44 Correct 796 ms 47480 KB Output is correct
45 Correct 817 ms 47600 KB Output is correct
46 Correct 800 ms 47608 KB Output is correct
47 Correct 797 ms 47480 KB Output is correct
48 Correct 813 ms 47480 KB Output is correct
49 Correct 790 ms 47736 KB Output is correct
50 Correct 794 ms 47608 KB Output is correct
51 Correct 799 ms 47484 KB Output is correct
52 Correct 810 ms 47480 KB Output is correct
53 Correct 823 ms 47608 KB Output is correct
54 Correct 806 ms 47736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 7 ms 508 KB Output is correct
4 Correct 6 ms 504 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 376 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 416 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 508 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 827 ms 47608 KB Output is correct
34 Correct 819 ms 47608 KB Output is correct
35 Correct 809 ms 47480 KB Output is correct
36 Correct 804 ms 47480 KB Output is correct
37 Correct 813 ms 47600 KB Output is correct
38 Correct 813 ms 47608 KB Output is correct
39 Correct 801 ms 47608 KB Output is correct
40 Correct 814 ms 47608 KB Output is correct
41 Correct 838 ms 47608 KB Output is correct
42 Correct 799 ms 47608 KB Output is correct
43 Correct 808 ms 47584 KB Output is correct
44 Correct 796 ms 47480 KB Output is correct
45 Correct 817 ms 47600 KB Output is correct
46 Correct 800 ms 47608 KB Output is correct
47 Correct 797 ms 47480 KB Output is correct
48 Correct 813 ms 47480 KB Output is correct
49 Correct 790 ms 47736 KB Output is correct
50 Correct 794 ms 47608 KB Output is correct
51 Correct 799 ms 47484 KB Output is correct
52 Correct 810 ms 47480 KB Output is correct
53 Correct 823 ms 47608 KB Output is correct
54 Correct 806 ms 47736 KB Output is correct
55 Correct 807 ms 47600 KB Output is correct
56 Correct 810 ms 47608 KB Output is correct
57 Correct 825 ms 47608 KB Output is correct
58 Correct 829 ms 47608 KB Output is correct
59 Correct 807 ms 47480 KB Output is correct
60 Correct 815 ms 47608 KB Output is correct
61 Correct 805 ms 47480 KB Output is correct
62 Correct 805 ms 47612 KB Output is correct
63 Correct 819 ms 47608 KB Output is correct
64 Correct 811 ms 47608 KB Output is correct
65 Correct 794 ms 47480 KB Output is correct
66 Correct 811 ms 47480 KB Output is correct
67 Correct 799 ms 47480 KB Output is correct
68 Correct 820 ms 47736 KB Output is correct
69 Correct 813 ms 47480 KB Output is correct
70 Correct 829 ms 47608 KB Output is correct
71 Correct 799 ms 47608 KB Output is correct
72 Correct 819 ms 47608 KB Output is correct
73 Correct 834 ms 47736 KB Output is correct
74 Correct 819 ms 47736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 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 5 ms 508 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 6 ms 632 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 376 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 6 ms 504 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 7 ms 508 KB Output is correct
19 Correct 6 ms 504 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 376 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 416 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 508 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 827 ms 47608 KB Output is correct
49 Correct 819 ms 47608 KB Output is correct
50 Correct 809 ms 47480 KB Output is correct
51 Correct 804 ms 47480 KB Output is correct
52 Correct 813 ms 47600 KB Output is correct
53 Correct 813 ms 47608 KB Output is correct
54 Correct 801 ms 47608 KB Output is correct
55 Correct 814 ms 47608 KB Output is correct
56 Correct 838 ms 47608 KB Output is correct
57 Correct 799 ms 47608 KB Output is correct
58 Correct 808 ms 47584 KB Output is correct
59 Correct 796 ms 47480 KB Output is correct
60 Correct 817 ms 47600 KB Output is correct
61 Correct 800 ms 47608 KB Output is correct
62 Correct 797 ms 47480 KB Output is correct
63 Correct 813 ms 47480 KB Output is correct
64 Correct 790 ms 47736 KB Output is correct
65 Correct 794 ms 47608 KB Output is correct
66 Correct 799 ms 47484 KB Output is correct
67 Correct 810 ms 47480 KB Output is correct
68 Correct 823 ms 47608 KB Output is correct
69 Correct 806 ms 47736 KB Output is correct
70 Correct 807 ms 47600 KB Output is correct
71 Correct 810 ms 47608 KB Output is correct
72 Correct 825 ms 47608 KB Output is correct
73 Correct 829 ms 47608 KB Output is correct
74 Correct 807 ms 47480 KB Output is correct
75 Correct 815 ms 47608 KB Output is correct
76 Correct 805 ms 47480 KB Output is correct
77 Correct 805 ms 47612 KB Output is correct
78 Correct 819 ms 47608 KB Output is correct
79 Correct 811 ms 47608 KB Output is correct
80 Correct 794 ms 47480 KB Output is correct
81 Correct 811 ms 47480 KB Output is correct
82 Correct 799 ms 47480 KB Output is correct
83 Correct 820 ms 47736 KB Output is correct
84 Correct 813 ms 47480 KB Output is correct
85 Correct 829 ms 47608 KB Output is correct
86 Correct 799 ms 47608 KB Output is correct
87 Correct 819 ms 47608 KB Output is correct
88 Correct 834 ms 47736 KB Output is correct
89 Correct 819 ms 47736 KB Output is correct
90 Correct 818 ms 47624 KB Output is correct
91 Correct 804 ms 47608 KB Output is correct
92 Correct 817 ms 47608 KB Output is correct
93 Correct 813 ms 47612 KB Output is correct
94 Correct 813 ms 47608 KB Output is correct
95 Correct 812 ms 47608 KB Output is correct
96 Correct 795 ms 47608 KB Output is correct
97 Correct 827 ms 47736 KB Output is correct
98 Correct 803 ms 47480 KB Output is correct
99 Correct 810 ms 47608 KB Output is correct
100 Correct 636 ms 47568 KB Output is correct
101 Correct 656 ms 47480 KB Output is correct
102 Correct 670 ms 47480 KB Output is correct
103 Correct 638 ms 47736 KB Output is correct
104 Correct 649 ms 47608 KB Output is correct
105 Correct 685 ms 47608 KB Output is correct
106 Correct 688 ms 47616 KB Output is correct
107 Correct 694 ms 47632 KB Output is correct
108 Correct 724 ms 47628 KB Output is correct
109 Correct 695 ms 47608 KB Output is correct
110 Correct 764 ms 47736 KB Output is correct
111 Correct 763 ms 47608 KB Output is correct
112 Correct 766 ms 47608 KB Output is correct
113 Correct 745 ms 47608 KB Output is correct
114 Correct 781 ms 47736 KB Output is correct
115 Correct 814 ms 47608 KB Output is correct
116 Correct 810 ms 47608 KB Output is correct
117 Correct 762 ms 47608 KB Output is correct
118 Correct 768 ms 47692 KB Output is correct
119 Correct 775 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 829 ms 47480 KB Output is correct
123 Correct 878 ms 47736 KB Output is correct
124 Correct 822 ms 47712 KB Output is correct
125 Correct 809 ms 47608 KB Output is correct
126 Correct 811 ms 47480 KB Output is correct
127 Correct 818 ms 47708 KB Output is correct
128 Correct 809 ms 47480 KB Output is correct
129 Correct 814 ms 47608 KB Output is correct
130 Correct 819 ms 47608 KB Output is correct
131 Correct 843 ms 47736 KB Output is correct
132 Correct 838 ms 47600 KB Output is correct
133 Correct 822 ms 47484 KB Output is correct