답안 #590537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590537 2022-07-06T05:53:13 Z 조영욱(#8414) Bulldozer (JOI17_bulldozer) C++17
100 / 100
1220 ms 95300 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

typedef pair<int,int> P;
typedef pair<P,int> Pi;
Pi arr[2000];
Pi arr1[2000];
typedef pair<P,P> PP;
vector<PP> vec;

long long ccw(P a,P b,P c) {
    return 1LL*a.first*b.second+1LL*b.first*c.second+1LL*c.first*a.second-1LL*a.second*b.first-1LL*b.second*c.first-1LL*c.second*a.first;
}

bool comp(PP a,PP b) {
    return 1LL*a.first.first*b.first.second-1LL*a.first.second*b.first.first>0;
}

bool comp1(Pi a,Pi b) {
    if (a.first.first==b.first.first) {
        return a.first.second<b.first.second;
    }
    return a.first.first<b.first.first;
}

int pos[2000];
int rev[2000];

struct Node {
    long long lsum,rsum,lrsum,sum;
};

const int sz=2048;
Node seg[sz*2];

Node merge(Node l,Node r) {
    Node ret;
    ret.lsum=max(l.lsum,l.sum+r.lsum);
    ret.rsum=max(r.rsum,r.sum+l.rsum);
    ret.lrsum=max({l.lrsum,r.lrsum,l.rsum+r.lsum});
    ret.sum=l.sum+r.sum;
    return ret;
}

Node sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
    if (r<nodel||l>noder) {
        return {0,0,0,0};
    }
    if (l<=nodel&&noder<=r) {
        return seg[node];
    }
    int mid=(nodel+noder)/2;
    return merge(sum(l,r,node*2,nodel,mid),sum(l,r,node*2+1,mid+1,noder));
}

void update(int i,int val) {
    i+=sz;
    seg[i]={val<0?0:val,val<0?0:val,val<0?0:val,val};
    while (i>1) {
        i/=2;
        seg[i]=merge(seg[i*2],seg[i*2+1]);
    }
}

main() {
    int n;
    scanf("%lld",&n);
    for(int i=0;i<n;i++) {
        scanf("%lld %lld %lld",&arr[i].first.first,&arr[i].first.second,&arr[i].second);
        arr1[i]=Pi(arr[i].first,i);
    }
    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++) {
            int dx=arr[j].first.first-arr[i].first.first;
            int dy=arr[j].first.second-arr[i].first.second;
            swap(dx,dy);
            dy=-dy;
            if (dy<0) {
                dy=-dy;
                dx=-dx;
            }
            if (dy==0&&dx>0) {
                dx=-dx;
            }
            //printf("%d %d %d %d\n",i,j,dx,dy);
            vec.push_back(PP(P(dx,dy),P(i,j)));
        }
    }
    sort(vec.begin(),vec.end(),comp);
    sort(arr1,arr1+n,comp1);
    for(int i=0;i<n;i++) {
        pos[arr1[i].second]=i;
        rev[i]=arr1[i].second;
        update(i,arr[rev[i]].second);
    }
    vector<int> temp;
    long long ret=sum(0,n-1).lrsum;
    for(int ind=0;ind<vec.size();ind++) {
        //printf("%d %d\n",pos[vec[ind].second.first],pos[vec[ind].second.second]);
        ret=max(ret,sum(0,n-1).lrsum);
        PP now=vec[ind];
        temp.push_back(pos[vec[ind].second.first]);
        temp.push_back(pos[vec[ind].second.second]);
        if (ind+1!=vec.size()&&(!comp(vec[ind],vec[ind+1])&&!comp(vec[ind+1],vec[ind]))) {
            continue;
        }
        sort(temp.begin(),temp.end());
        temp.erase(unique(temp.begin(),temp.end()),temp.end());
        //printf("%d\n",temp.size());
        int in=0;
        while (in<temp.size()) {
            int mnpos=temp[in];
            in++;
            while (1) {
                if (in+1==temp.size()) {
                    break;
                }
                int pr=rev[temp[in-1]];
                int now=rev[temp[in]];
                int nt=rev[temp[in+1]];
                if (ccw(arr[pr].first,arr[now].first,arr[nt].first)!=0) {
                    break;
                }
                in++;
            }
            int mxpos=temp[in];
            for(int i=mnpos;i<=mxpos;i++) {
                update(i,0);
            }
            for(int i=mnpos;i<=mxpos;i++) {
                int j=mnpos+mxpos-i;
                if (i>j) {
                    break;
                }
                swap(rev[i],rev[j]);
                pos[rev[i]]=i;
                pos[rev[j]]=j;
                update(i,arr[rev[i]].second);
                update(j,arr[rev[j]].second);
            }
            in++;
        }
        temp.clear();
    }
    printf("%lld",ret);
    return 0;
}

Compilation message

bulldozer.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main() {
      | ^~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:100:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for(int ind=0;ind<vec.size();ind++) {
      |                   ~~~^~~~~~~~~~~
bulldozer.cpp:106:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         if (ind+1!=vec.size()&&(!comp(vec[ind],vec[ind+1])&&!comp(vec[ind+1],vec[ind]))) {
      |             ~~~~~^~~~~~~~~~~~
bulldozer.cpp:113:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         while (in<temp.size()) {
      |                ~~^~~~~~~~~~~~
bulldozer.cpp:117:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |                 if (in+1==temp.size()) {
      |                     ~~~~^~~~~~~~~~~~~
bulldozer.cpp:103:12: warning: variable 'now' set but not used [-Wunused-but-set-variable]
  103 |         PP now=vec[ind];
      |            ^~~
bulldozer.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
bulldozer.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf("%lld %lld %lld",&arr[i].first.first,&arr[i].first.second,&arr[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 720 KB Output is correct
3 Correct 2 ms 720 KB Output is correct
4 Correct 3 ms 720 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 5 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 5 ms 612 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 4 ms 596 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 5 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 5 ms 612 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 4 ms 596 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 1163 ms 66064 KB Output is correct
34 Correct 1160 ms 66188 KB Output is correct
35 Correct 1158 ms 66188 KB Output is correct
36 Correct 1153 ms 66132 KB Output is correct
37 Correct 1150 ms 66112 KB Output is correct
38 Correct 1212 ms 66092 KB Output is correct
39 Correct 1152 ms 66132 KB Output is correct
40 Correct 1179 ms 66188 KB Output is correct
41 Correct 1139 ms 66224 KB Output is correct
42 Correct 1196 ms 66188 KB Output is correct
43 Correct 1170 ms 66124 KB Output is correct
44 Correct 1199 ms 66204 KB Output is correct
45 Correct 1166 ms 66148 KB Output is correct
46 Correct 1163 ms 66212 KB Output is correct
47 Correct 1177 ms 66192 KB Output is correct
48 Correct 1172 ms 66192 KB Output is correct
49 Correct 1142 ms 66152 KB Output is correct
50 Correct 1162 ms 66156 KB Output is correct
51 Correct 1132 ms 66160 KB Output is correct
52 Correct 1170 ms 66184 KB Output is correct
53 Correct 1186 ms 66308 KB Output is correct
54 Correct 1137 ms 66128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 5 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 5 ms 612 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 4 ms 596 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 1163 ms 66064 KB Output is correct
34 Correct 1160 ms 66188 KB Output is correct
35 Correct 1158 ms 66188 KB Output is correct
36 Correct 1153 ms 66132 KB Output is correct
37 Correct 1150 ms 66112 KB Output is correct
38 Correct 1212 ms 66092 KB Output is correct
39 Correct 1152 ms 66132 KB Output is correct
40 Correct 1179 ms 66188 KB Output is correct
41 Correct 1139 ms 66224 KB Output is correct
42 Correct 1196 ms 66188 KB Output is correct
43 Correct 1170 ms 66124 KB Output is correct
44 Correct 1199 ms 66204 KB Output is correct
45 Correct 1166 ms 66148 KB Output is correct
46 Correct 1163 ms 66212 KB Output is correct
47 Correct 1177 ms 66192 KB Output is correct
48 Correct 1172 ms 66192 KB Output is correct
49 Correct 1142 ms 66152 KB Output is correct
50 Correct 1162 ms 66156 KB Output is correct
51 Correct 1132 ms 66160 KB Output is correct
52 Correct 1170 ms 66184 KB Output is correct
53 Correct 1186 ms 66308 KB Output is correct
54 Correct 1137 ms 66128 KB Output is correct
55 Correct 1202 ms 66188 KB Output is correct
56 Correct 1155 ms 66128 KB Output is correct
57 Correct 1155 ms 66188 KB Output is correct
58 Correct 1184 ms 66184 KB Output is correct
59 Correct 1184 ms 66132 KB Output is correct
60 Correct 1169 ms 66140 KB Output is correct
61 Correct 1142 ms 66256 KB Output is correct
62 Correct 1170 ms 66160 KB Output is correct
63 Correct 1153 ms 66188 KB Output is correct
64 Correct 1154 ms 66180 KB Output is correct
65 Correct 1180 ms 66172 KB Output is correct
66 Correct 1159 ms 66108 KB Output is correct
67 Correct 1169 ms 66100 KB Output is correct
68 Correct 1163 ms 66092 KB Output is correct
69 Correct 1161 ms 66064 KB Output is correct
70 Correct 1168 ms 66240 KB Output is correct
71 Correct 1129 ms 66132 KB Output is correct
72 Correct 1125 ms 66152 KB Output is correct
73 Correct 1149 ms 66204 KB Output is correct
74 Correct 1198 ms 66064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 720 KB Output is correct
3 Correct 2 ms 720 KB Output is correct
4 Correct 3 ms 720 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 5 ms 612 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 4 ms 596 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 3 ms 596 KB Output is correct
38 Correct 3 ms 596 KB Output is correct
39 Correct 3 ms 596 KB Output is correct
40 Correct 4 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 596 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 596 KB Output is correct
48 Correct 1163 ms 66064 KB Output is correct
49 Correct 1160 ms 66188 KB Output is correct
50 Correct 1158 ms 66188 KB Output is correct
51 Correct 1153 ms 66132 KB Output is correct
52 Correct 1150 ms 66112 KB Output is correct
53 Correct 1212 ms 66092 KB Output is correct
54 Correct 1152 ms 66132 KB Output is correct
55 Correct 1179 ms 66188 KB Output is correct
56 Correct 1139 ms 66224 KB Output is correct
57 Correct 1196 ms 66188 KB Output is correct
58 Correct 1170 ms 66124 KB Output is correct
59 Correct 1199 ms 66204 KB Output is correct
60 Correct 1166 ms 66148 KB Output is correct
61 Correct 1163 ms 66212 KB Output is correct
62 Correct 1177 ms 66192 KB Output is correct
63 Correct 1172 ms 66192 KB Output is correct
64 Correct 1142 ms 66152 KB Output is correct
65 Correct 1162 ms 66156 KB Output is correct
66 Correct 1132 ms 66160 KB Output is correct
67 Correct 1170 ms 66184 KB Output is correct
68 Correct 1186 ms 66308 KB Output is correct
69 Correct 1137 ms 66128 KB Output is correct
70 Correct 1202 ms 66188 KB Output is correct
71 Correct 1155 ms 66128 KB Output is correct
72 Correct 1155 ms 66188 KB Output is correct
73 Correct 1184 ms 66184 KB Output is correct
74 Correct 1184 ms 66132 KB Output is correct
75 Correct 1169 ms 66140 KB Output is correct
76 Correct 1142 ms 66256 KB Output is correct
77 Correct 1170 ms 66160 KB Output is correct
78 Correct 1153 ms 66188 KB Output is correct
79 Correct 1154 ms 66180 KB Output is correct
80 Correct 1180 ms 66172 KB Output is correct
81 Correct 1159 ms 66108 KB Output is correct
82 Correct 1169 ms 66100 KB Output is correct
83 Correct 1163 ms 66092 KB Output is correct
84 Correct 1161 ms 66064 KB Output is correct
85 Correct 1168 ms 66240 KB Output is correct
86 Correct 1129 ms 66132 KB Output is correct
87 Correct 1125 ms 66152 KB Output is correct
88 Correct 1149 ms 66204 KB Output is correct
89 Correct 1198 ms 66064 KB Output is correct
90 Correct 1144 ms 66188 KB Output is correct
91 Correct 1153 ms 66140 KB Output is correct
92 Correct 1133 ms 66132 KB Output is correct
93 Correct 1179 ms 66096 KB Output is correct
94 Correct 1139 ms 66120 KB Output is correct
95 Correct 1220 ms 66172 KB Output is correct
96 Correct 1141 ms 66284 KB Output is correct
97 Correct 1136 ms 66148 KB Output is correct
98 Correct 1136 ms 66164 KB Output is correct
99 Correct 1168 ms 66368 KB Output is correct
100 Correct 917 ms 95300 KB Output is correct
101 Correct 983 ms 95176 KB Output is correct
102 Correct 932 ms 95140 KB Output is correct
103 Correct 928 ms 95200 KB Output is correct
104 Correct 939 ms 95112 KB Output is correct
105 Correct 1018 ms 89896 KB Output is correct
106 Correct 997 ms 90176 KB Output is correct
107 Correct 1000 ms 90096 KB Output is correct
108 Correct 1008 ms 89996 KB Output is correct
109 Correct 994 ms 89900 KB Output is correct
110 Correct 980 ms 66160 KB Output is correct
111 Correct 987 ms 66320 KB Output is correct
112 Correct 978 ms 66156 KB Output is correct
113 Correct 970 ms 66228 KB Output is correct
114 Correct 991 ms 66188 KB Output is correct
115 Correct 1054 ms 66156 KB Output is correct
116 Correct 973 ms 66156 KB Output is correct
117 Correct 1014 ms 66208 KB Output is correct
118 Correct 984 ms 66252 KB Output is correct
119 Correct 997 ms 66168 KB Output is correct
120 Correct 1 ms 340 KB Output is correct
121 Correct 1 ms 340 KB Output is correct
122 Correct 1190 ms 66264 KB Output is correct
123 Correct 1134 ms 66188 KB Output is correct
124 Correct 1148 ms 66156 KB Output is correct
125 Correct 1146 ms 66256 KB Output is correct
126 Correct 1153 ms 66152 KB Output is correct
127 Correct 1170 ms 66324 KB Output is correct
128 Correct 1136 ms 66236 KB Output is correct
129 Correct 1127 ms 66188 KB Output is correct
130 Correct 1157 ms 66224 KB Output is correct
131 Correct 1136 ms 66188 KB Output is correct
132 Correct 1162 ms 66156 KB Output is correct
133 Correct 1183 ms 66200 KB Output is correct