답안 #590536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590536 2022-07-06T05:47:16 Z 조영욱(#8414) Bulldozer (JOI17_bulldozer) C++17
80 / 100
1297 ms 95476 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 2 ms 720 KB Output is correct
2 Correct 2 ms 648 KB Output is correct
3 Correct 4 ms 720 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 3 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 3 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 3 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 1 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 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 5 ms 596 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 3 ms 692 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 3 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 3 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 1 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 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 5 ms 596 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 3 ms 692 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
33 Correct 1178 ms 66232 KB Output is correct
34 Correct 1194 ms 66220 KB Output is correct
35 Correct 1182 ms 66248 KB Output is correct
36 Correct 1174 ms 66184 KB Output is correct
37 Correct 1208 ms 66188 KB Output is correct
38 Correct 1169 ms 66256 KB Output is correct
39 Correct 1207 ms 66188 KB Output is correct
40 Correct 1183 ms 66220 KB Output is correct
41 Correct 1198 ms 66128 KB Output is correct
42 Correct 1196 ms 66180 KB Output is correct
43 Correct 1212 ms 66156 KB Output is correct
44 Correct 1164 ms 66272 KB Output is correct
45 Correct 1166 ms 66212 KB Output is correct
46 Correct 1193 ms 66156 KB Output is correct
47 Correct 1166 ms 66188 KB Output is correct
48 Correct 1178 ms 66264 KB Output is correct
49 Correct 1164 ms 66168 KB Output is correct
50 Correct 1205 ms 66156 KB Output is correct
51 Correct 1163 ms 66188 KB Output is correct
52 Correct 1200 ms 66260 KB Output is correct
53 Correct 1204 ms 66156 KB Output is correct
54 Correct 1174 ms 66276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 3 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 3 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 1 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 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 5 ms 596 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 596 KB Output is correct
25 Correct 3 ms 692 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
33 Correct 1178 ms 66232 KB Output is correct
34 Correct 1194 ms 66220 KB Output is correct
35 Correct 1182 ms 66248 KB Output is correct
36 Correct 1174 ms 66184 KB Output is correct
37 Correct 1208 ms 66188 KB Output is correct
38 Correct 1169 ms 66256 KB Output is correct
39 Correct 1207 ms 66188 KB Output is correct
40 Correct 1183 ms 66220 KB Output is correct
41 Correct 1198 ms 66128 KB Output is correct
42 Correct 1196 ms 66180 KB Output is correct
43 Correct 1212 ms 66156 KB Output is correct
44 Correct 1164 ms 66272 KB Output is correct
45 Correct 1166 ms 66212 KB Output is correct
46 Correct 1193 ms 66156 KB Output is correct
47 Correct 1166 ms 66188 KB Output is correct
48 Correct 1178 ms 66264 KB Output is correct
49 Correct 1164 ms 66168 KB Output is correct
50 Correct 1205 ms 66156 KB Output is correct
51 Correct 1163 ms 66188 KB Output is correct
52 Correct 1200 ms 66260 KB Output is correct
53 Correct 1204 ms 66156 KB Output is correct
54 Correct 1174 ms 66276 KB Output is correct
55 Correct 1236 ms 66268 KB Output is correct
56 Correct 1212 ms 66168 KB Output is correct
57 Correct 1244 ms 66188 KB Output is correct
58 Correct 1232 ms 66188 KB Output is correct
59 Correct 1188 ms 66156 KB Output is correct
60 Correct 1185 ms 66284 KB Output is correct
61 Correct 1158 ms 66188 KB Output is correct
62 Correct 1291 ms 66264 KB Output is correct
63 Correct 1197 ms 66280 KB Output is correct
64 Correct 1297 ms 66156 KB Output is correct
65 Correct 1195 ms 66260 KB Output is correct
66 Correct 1172 ms 66264 KB Output is correct
67 Correct 1295 ms 66160 KB Output is correct
68 Correct 1165 ms 66276 KB Output is correct
69 Correct 1166 ms 66160 KB Output is correct
70 Correct 1247 ms 66284 KB Output is correct
71 Correct 1195 ms 66152 KB Output is correct
72 Correct 1166 ms 66180 KB Output is correct
73 Correct 1235 ms 66228 KB Output is correct
74 Correct 1197 ms 66196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 720 KB Output is correct
2 Correct 2 ms 648 KB Output is correct
3 Correct 4 ms 720 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 3 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 3 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 3 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 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 5 ms 596 KB Output is correct
38 Correct 3 ms 688 KB Output is correct
39 Correct 3 ms 596 KB Output is correct
40 Correct 3 ms 692 KB Output is correct
41 Correct 4 ms 724 KB Output is correct
42 Correct 4 ms 596 KB Output is correct
43 Correct 4 ms 596 KB Output is correct
44 Correct 5 ms 596 KB Output is correct
45 Correct 4 ms 724 KB Output is correct
46 Correct 3 ms 724 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 1178 ms 66232 KB Output is correct
49 Correct 1194 ms 66220 KB Output is correct
50 Correct 1182 ms 66248 KB Output is correct
51 Correct 1174 ms 66184 KB Output is correct
52 Correct 1208 ms 66188 KB Output is correct
53 Correct 1169 ms 66256 KB Output is correct
54 Correct 1207 ms 66188 KB Output is correct
55 Correct 1183 ms 66220 KB Output is correct
56 Correct 1198 ms 66128 KB Output is correct
57 Correct 1196 ms 66180 KB Output is correct
58 Correct 1212 ms 66156 KB Output is correct
59 Correct 1164 ms 66272 KB Output is correct
60 Correct 1166 ms 66212 KB Output is correct
61 Correct 1193 ms 66156 KB Output is correct
62 Correct 1166 ms 66188 KB Output is correct
63 Correct 1178 ms 66264 KB Output is correct
64 Correct 1164 ms 66168 KB Output is correct
65 Correct 1205 ms 66156 KB Output is correct
66 Correct 1163 ms 66188 KB Output is correct
67 Correct 1200 ms 66260 KB Output is correct
68 Correct 1204 ms 66156 KB Output is correct
69 Correct 1174 ms 66276 KB Output is correct
70 Correct 1236 ms 66268 KB Output is correct
71 Correct 1212 ms 66168 KB Output is correct
72 Correct 1244 ms 66188 KB Output is correct
73 Correct 1232 ms 66188 KB Output is correct
74 Correct 1188 ms 66156 KB Output is correct
75 Correct 1185 ms 66284 KB Output is correct
76 Correct 1158 ms 66188 KB Output is correct
77 Correct 1291 ms 66264 KB Output is correct
78 Correct 1197 ms 66280 KB Output is correct
79 Correct 1297 ms 66156 KB Output is correct
80 Correct 1195 ms 66260 KB Output is correct
81 Correct 1172 ms 66264 KB Output is correct
82 Correct 1295 ms 66160 KB Output is correct
83 Correct 1165 ms 66276 KB Output is correct
84 Correct 1166 ms 66160 KB Output is correct
85 Correct 1247 ms 66284 KB Output is correct
86 Correct 1195 ms 66152 KB Output is correct
87 Correct 1166 ms 66180 KB Output is correct
88 Correct 1235 ms 66228 KB Output is correct
89 Correct 1197 ms 66196 KB Output is correct
90 Correct 1163 ms 66260 KB Output is correct
91 Correct 1185 ms 66200 KB Output is correct
92 Correct 1182 ms 66148 KB Output is correct
93 Correct 1242 ms 66164 KB Output is correct
94 Correct 1207 ms 66188 KB Output is correct
95 Correct 1176 ms 66224 KB Output is correct
96 Correct 1189 ms 66196 KB Output is correct
97 Correct 1183 ms 66196 KB Output is correct
98 Correct 1191 ms 66184 KB Output is correct
99 Correct 1169 ms 66208 KB Output is correct
100 Correct 957 ms 95360 KB Output is correct
101 Correct 939 ms 95476 KB Output is correct
102 Correct 938 ms 95288 KB Output is correct
103 Correct 943 ms 95224 KB Output is correct
104 Correct 964 ms 95412 KB Output is correct
105 Correct 996 ms 90040 KB Output is correct
106 Correct 1038 ms 89944 KB Output is correct
107 Correct 1027 ms 90052 KB Output is correct
108 Correct 1006 ms 90000 KB Output is correct
109 Correct 1010 ms 90036 KB Output is correct
110 Incorrect 988 ms 66128 KB Output isn't correct
111 Halted 0 ms 0 KB -