Submission #238500

# Submission time Handle Problem Language Result Execution time Memory
238500 2020-06-11T15:01:59 Z m3r8 Bulldozer (JOI17_bulldozer) C++14
100 / 100
1509 ms 37540 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>

#define ii std::pair<int,int>
#define iil std::pair<long long,long long>
#define ll long long
#define N 2200
#define left(i) (i << 1)
#define right(i) ((i << 1)+1)

typedef struct trr{
  ll pre;
  ll suf;
  ll best;
  ll sum;
}trr;

trr seg[N * 4];

void update(int idx, int l, int r, int v, ll x){
  if(l >= r)return;  
  if(l == r-1){
    if(x > 0){
      seg[idx].pre = x;  
      seg[idx].suf = x;
      seg[idx].best = x;    
    }else{
      seg[idx].pre = 0;  
      seg[idx].suf = 0;
      seg[idx].best = 0;    
    };
    seg[idx].sum = x;
  }else{
    int m = (l + r)>>1;
    if(v < m){
      update(left(idx),l,m,v,x);
    }else{
      update(right(idx),m,r,v,x);
    };  
    seg[idx].pre = std::max(seg[left(idx)].pre,seg[right(idx)].pre + seg[left(idx)].sum);
    seg[idx].suf = std::max(seg[right(idx)].suf,seg[left(idx)].suf + seg[right(idx)].sum);
    seg[idx].sum = seg[left(idx)].sum + seg[right(idx)].sum;
    seg[idx].best = std::max(seg[left(idx)].best,seg[right(idx)].best);
    seg[idx].best = std::max(seg[idx].best,seg[left(idx)].suf + seg[right(idx)].pre);
  };
};


long long ccw(iil a, iil b){
  return a.first * b.second - b.first * a.second;  
};

iil pp[N];
std::vector<ii> evt;
int pos[N];
int used[N];
ll value[N];
std::vector<int> col[N];
std::vector<ii> aktEvt;
int n;

int preCmp(int a, int b){
  return pos[a] < pos[b];  
};

int ptsCmp(int a, int b){
  if(pp[a].second != pp[b].second)return pp[a].second < pp[b].second;
  else return pp[a].first < pp[b].first;
};

ll evtCmp(ii a, ii b){
  ll x1 = pp[a.first].first-pp[a.second].first;  
  ll y1 = pp[a.first].second-pp[a.second].second;
  if(y1 < 0){
    x1 *= -1;  
    y1 *= -1;
  };
  if(y1 == 0){
    x1 = std::abs(x1);  
  };

  ll x2 = pp[b.first].first - pp[b.second].first;
  ll y2 = pp[b.first].second - pp[b.second].second;
  if(y2 < 0){
    x2 *= -1;  
    y2 *= -1;
  };
  if(y2 == 0){
    x2 = std::abs(x2);  
  };

  return ccw({x1,y1},{x2,y2});
};

int evtCcmp(ii a, ii b){
  return evtCmp(a, b) > 0; 
}; 

void swp(int idx1, int idx2){
  update(1,0,n,pos[idx1],value[idx2]);  
  update(1,0,n,pos[idx2],value[idx1]);  
  int tmp = pos[idx1];
  pos[idx1] = pos[idx2];
  pos[idx2] = tmp;
};


void handleCo(int idx){
  col[idx].push_back(idx);
  std::sort(col[idx].begin(),col[idx].end(),preCmp);  
  int len = col[idx].size();
  for(int i = 0;i<len>>1;i++){
    swp(col[idx][i], col[idx][len-i-1]);
  };
  for(auto i: col[idx]){
    used[i] = 1;  
  };
};

ll handleEvt(){
  for(auto i: aktEvt){
    col[i.first].push_back(i.second);
    col[i.second].push_back(i.first);
  };  
  for(auto i: aktEvt){
    if(!used[i.first]){
      handleCo(i.first);
    };  
  };
  for(auto i: aktEvt){
    used[i.first] = 0;  
    used[i.second] = 0;
    col[i.first].clear();
    col[i.second].clear();
  };
  return seg[1].best;
};

std::vector<int> pts;

int main(void){
  scanf("%d",&n);  
  for(int i = 0;i<n;i++){
    scanf("%lld %lld %lld\n",&(pp[i].first),&(pp[i].second),&value[i]);  
  };
  for(int i = 0;i<n;i++){
    for(int j = 0;j<i;j++){
      evt.push_back({i,j});
    };  
  };
  std::sort(evt.begin(),evt.end(),evtCcmp);
  for(int i = 0;i<n;i++){
    pts.push_back(i);
  };
  std::sort(pts.begin(),pts.end(),ptsCmp);
  for(int i = 0;i<n;i++){
    pos[pts[i]] = i;  
  };
  /*
  for(int i = 0;i<n;i++){
    printf("%d %d\n",i,pos[i]);  
  };
  puts("");
  */
  for(int i = 0;i<n;i++){
    update(1,0,n,i,value[pts[i]]);  
  };
  ll mx = 0;
  mx = std::max(mx,seg[1].best);
 // printf("%d\n",mx);
  int idx = 0;
  while(idx < evt.size()){
    aktEvt.push_back(evt[idx]);
    while(idx < evt.size()-1 && evtCmp(evt[idx],evt[idx+1]) == 0){
      aktEvt.push_back(evt[++idx]);
    };  
    mx = std::max(mx,handleEvt());
    /*
    printf("%d\n",mx);
    printf("%d %d %d\n\n",aktEvt[0].first,aktEvt[0].second,aktEvt.size());
    for(int i = 0;i<n;i++){
      printf("%d %d\n",i,pos[i]);  
    };
    puts("");
    */
    aktEvt.clear();
    idx++;
  };
  printf("%lld\n", mx);
  return 0;
};

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:175:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(idx < evt.size()){
         ~~~~^~~~~~~~~~~~
bulldozer.cpp:177:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(idx < evt.size()-1 && evtCmp(evt[idx],evt[idx+1]) == 0){
           ~~~~^~~~~~~~~~~~~~
bulldozer.cpp:145:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);  
   ~~~~~^~~~~~~~~
bulldozer.cpp:147:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld %lld\n",&(pp[i].first),&(pp[i].second),&value[i]);  
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 544 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 8 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 512 KB Output is correct
31 Correct 7 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 544 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 8 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 512 KB Output is correct
31 Correct 7 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 1479 ms 17000 KB Output is correct
34 Correct 1484 ms 17000 KB Output is correct
35 Correct 1495 ms 17000 KB Output is correct
36 Correct 1498 ms 17000 KB Output is correct
37 Correct 1505 ms 17000 KB Output is correct
38 Correct 1492 ms 16992 KB Output is correct
39 Correct 1477 ms 17000 KB Output is correct
40 Correct 1486 ms 17000 KB Output is correct
41 Correct 1495 ms 17000 KB Output is correct
42 Correct 1489 ms 17000 KB Output is correct
43 Correct 1349 ms 17000 KB Output is correct
44 Correct 1343 ms 17000 KB Output is correct
45 Correct 1344 ms 17000 KB Output is correct
46 Correct 1345 ms 17000 KB Output is correct
47 Correct 1339 ms 17128 KB Output is correct
48 Correct 1344 ms 17128 KB Output is correct
49 Correct 1313 ms 17000 KB Output is correct
50 Correct 1330 ms 17128 KB Output is correct
51 Correct 1313 ms 17000 KB Output is correct
52 Correct 1323 ms 17000 KB Output is correct
53 Correct 1320 ms 17128 KB Output is correct
54 Correct 1318 ms 17000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 544 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 8 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 512 KB Output is correct
31 Correct 7 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 1479 ms 17000 KB Output is correct
34 Correct 1484 ms 17000 KB Output is correct
35 Correct 1495 ms 17000 KB Output is correct
36 Correct 1498 ms 17000 KB Output is correct
37 Correct 1505 ms 17000 KB Output is correct
38 Correct 1492 ms 16992 KB Output is correct
39 Correct 1477 ms 17000 KB Output is correct
40 Correct 1486 ms 17000 KB Output is correct
41 Correct 1495 ms 17000 KB Output is correct
42 Correct 1489 ms 17000 KB Output is correct
43 Correct 1349 ms 17000 KB Output is correct
44 Correct 1343 ms 17000 KB Output is correct
45 Correct 1344 ms 17000 KB Output is correct
46 Correct 1345 ms 17000 KB Output is correct
47 Correct 1339 ms 17128 KB Output is correct
48 Correct 1344 ms 17128 KB Output is correct
49 Correct 1313 ms 17000 KB Output is correct
50 Correct 1330 ms 17128 KB Output is correct
51 Correct 1313 ms 17000 KB Output is correct
52 Correct 1323 ms 17000 KB Output is correct
53 Correct 1320 ms 17128 KB Output is correct
54 Correct 1318 ms 17000 KB Output is correct
55 Correct 1486 ms 17000 KB Output is correct
56 Correct 1465 ms 17000 KB Output is correct
57 Correct 1471 ms 17000 KB Output is correct
58 Correct 1479 ms 16992 KB Output is correct
59 Correct 1483 ms 17000 KB Output is correct
60 Correct 1482 ms 17000 KB Output is correct
61 Correct 1487 ms 17128 KB Output is correct
62 Correct 1485 ms 17000 KB Output is correct
63 Correct 1483 ms 17128 KB Output is correct
64 Correct 1488 ms 17000 KB Output is correct
65 Correct 1489 ms 17000 KB Output is correct
66 Correct 1490 ms 17000 KB Output is correct
67 Correct 1474 ms 17128 KB Output is correct
68 Correct 1482 ms 17000 KB Output is correct
69 Correct 1488 ms 17000 KB Output is correct
70 Correct 1461 ms 17000 KB Output is correct
71 Correct 1478 ms 17128 KB Output is correct
72 Correct 1473 ms 17000 KB Output is correct
73 Correct 1484 ms 17000 KB Output is correct
74 Correct 1476 ms 17000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 7 ms 512 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 7 ms 512 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 7 ms 544 KB Output is correct
37 Correct 7 ms 512 KB Output is correct
38 Correct 7 ms 512 KB Output is correct
39 Correct 7 ms 512 KB Output is correct
40 Correct 7 ms 512 KB Output is correct
41 Correct 8 ms 512 KB Output is correct
42 Correct 7 ms 512 KB Output is correct
43 Correct 7 ms 512 KB Output is correct
44 Correct 7 ms 512 KB Output is correct
45 Correct 7 ms 512 KB Output is correct
46 Correct 7 ms 512 KB Output is correct
47 Correct 6 ms 512 KB Output is correct
48 Correct 1479 ms 17000 KB Output is correct
49 Correct 1484 ms 17000 KB Output is correct
50 Correct 1495 ms 17000 KB Output is correct
51 Correct 1498 ms 17000 KB Output is correct
52 Correct 1505 ms 17000 KB Output is correct
53 Correct 1492 ms 16992 KB Output is correct
54 Correct 1477 ms 17000 KB Output is correct
55 Correct 1486 ms 17000 KB Output is correct
56 Correct 1495 ms 17000 KB Output is correct
57 Correct 1489 ms 17000 KB Output is correct
58 Correct 1349 ms 17000 KB Output is correct
59 Correct 1343 ms 17000 KB Output is correct
60 Correct 1344 ms 17000 KB Output is correct
61 Correct 1345 ms 17000 KB Output is correct
62 Correct 1339 ms 17128 KB Output is correct
63 Correct 1344 ms 17128 KB Output is correct
64 Correct 1313 ms 17000 KB Output is correct
65 Correct 1330 ms 17128 KB Output is correct
66 Correct 1313 ms 17000 KB Output is correct
67 Correct 1323 ms 17000 KB Output is correct
68 Correct 1320 ms 17128 KB Output is correct
69 Correct 1318 ms 17000 KB Output is correct
70 Correct 1486 ms 17000 KB Output is correct
71 Correct 1465 ms 17000 KB Output is correct
72 Correct 1471 ms 17000 KB Output is correct
73 Correct 1479 ms 16992 KB Output is correct
74 Correct 1483 ms 17000 KB Output is correct
75 Correct 1482 ms 17000 KB Output is correct
76 Correct 1487 ms 17128 KB Output is correct
77 Correct 1485 ms 17000 KB Output is correct
78 Correct 1483 ms 17128 KB Output is correct
79 Correct 1488 ms 17000 KB Output is correct
80 Correct 1489 ms 17000 KB Output is correct
81 Correct 1490 ms 17000 KB Output is correct
82 Correct 1474 ms 17128 KB Output is correct
83 Correct 1482 ms 17000 KB Output is correct
84 Correct 1488 ms 17000 KB Output is correct
85 Correct 1461 ms 17000 KB Output is correct
86 Correct 1478 ms 17128 KB Output is correct
87 Correct 1473 ms 17000 KB Output is correct
88 Correct 1484 ms 17000 KB Output is correct
89 Correct 1476 ms 17000 KB Output is correct
90 Correct 1487 ms 17000 KB Output is correct
91 Correct 1487 ms 17000 KB Output is correct
92 Correct 1482 ms 17000 KB Output is correct
93 Correct 1497 ms 17128 KB Output is correct
94 Correct 1489 ms 17000 KB Output is correct
95 Correct 1494 ms 17000 KB Output is correct
96 Correct 1507 ms 17000 KB Output is correct
97 Correct 1495 ms 17000 KB Output is correct
98 Correct 1488 ms 17000 KB Output is correct
99 Correct 1509 ms 17000 KB Output is correct
100 Correct 969 ms 32700 KB Output is correct
101 Correct 976 ms 32828 KB Output is correct
102 Correct 1020 ms 37540 KB Output is correct
103 Correct 985 ms 32700 KB Output is correct
104 Correct 995 ms 32828 KB Output is correct
105 Correct 1167 ms 30144 KB Output is correct
106 Correct 1163 ms 30012 KB Output is correct
107 Correct 1145 ms 30272 KB Output is correct
108 Correct 1144 ms 30140 KB Output is correct
109 Correct 1147 ms 30140 KB Output is correct
110 Correct 917 ms 17052 KB Output is correct
111 Correct 917 ms 17084 KB Output is correct
112 Correct 922 ms 17084 KB Output is correct
113 Correct 935 ms 17084 KB Output is correct
114 Correct 923 ms 17084 KB Output is correct
115 Correct 928 ms 17084 KB Output is correct
116 Correct 918 ms 17000 KB Output is correct
117 Correct 920 ms 17000 KB Output is correct
118 Correct 932 ms 17084 KB Output is correct
119 Correct 913 ms 17084 KB Output is correct
120 Correct 4 ms 384 KB Output is correct
121 Correct 4 ms 384 KB Output is correct
122 Correct 1350 ms 17000 KB Output is correct
123 Correct 1357 ms 17000 KB Output is correct
124 Correct 1349 ms 17000 KB Output is correct
125 Correct 1345 ms 17000 KB Output is correct
126 Correct 1354 ms 17000 KB Output is correct
127 Correct 1352 ms 17000 KB Output is correct
128 Correct 1319 ms 17000 KB Output is correct
129 Correct 1331 ms 17000 KB Output is correct
130 Correct 1323 ms 17000 KB Output is correct
131 Correct 1321 ms 17000 KB Output is correct
132 Correct 1317 ms 17000 KB Output is correct
133 Correct 1326 ms 17128 KB Output is correct