Submission #1000590

# Submission time Handle Problem Language Result Execution time Memory
1000590 2024-06-17T22:15:42 Z AdamGS Bulldozer (JOI17_bulldozer) C++17
100 / 100
554 ms 68336 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=2e3+7;
pair<pair<ll,ll>,ll>T[LIM];
ll trmi[4*LIM], trma[4*LIM], trans[4*LIM], pos[LIM], N=1;
ll ilo(pair<ll,ll>a, pair<ll,ll>b) {
  return a.st*b.nd-a.nd*b.st;
} 
bool srt(pair<pair<ll,ll>,pair<ll,ll>>a, pair<pair<ll,ll>,pair<ll,ll>>b) {
  if(ilo(a.st, b.st)==0) return a.nd<b.nd;
  return ilo(a.st, b.st)>0;
}
void licz(int v) {
  trmi[v]=min(trmi[2*v], trmi[2*v+1]);
  trma[v]=max(trma[2*v], trma[2*v+1]);
  trans[v]=max(max(trans[2*v], trans[2*v+1]), trma[2*v+1]-trmi[2*v]);
}
void upd(int v, ll x) {
  v+=N;
  trmi[v]+=x;
  trma[v]+=x;
  v/=2;
  while(v) {
    licz(v);
    v/=2;
  }
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  while(N<n) N*=2;
  rep(i, n) cin >> T[i].st.st >> T[i].st.nd >> T[i].nd;
  rep(i, n) swap(T[i].st.st, T[i].st.nd);
  sort(T, T+n);
  rep(i, n) swap(T[i].st.st, T[i].st.nd);
  vector<pair<pair<ll,ll>,pair<ll,ll>>>V;
  rep(i, n) rep(j, i) V.pb({{T[i].st.st-T[j].st.st, T[i].st.nd-T[j].st.nd}, {j, i}});
  sort(all(V), srt);
  rep(i, n) {
    pos[i]=i;
    trmi[N+i]=trma[N+i]=T[i].nd+trmi[N+i-1];
  }
  for(int i=n; i<N; ++i) trmi[N+i]=trma[N+i]=trans[N+i]=-INF;
  for(int i=N-1; i; --i) licz(i);
  ll ans=max(trans[1], trma[1]);
  rep(i, V.size()) {
    int l=i;
    while(l<V.size() && ilo(V[l].st, V[i].st)==0) {
      upd(pos[V[l].nd.st], T[V[l].nd.nd].nd-T[V[l].nd.st].nd);
      swap(pos[V[l].nd.st], pos[V[l].nd.nd]);
      ++l;
    }
    ans=max(ans, max(trans[1], trma[1]));
    i=l-1;
  }
  cout << ans << '\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:5:36: warning: comparison of integer expressions of different signedness: '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]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
bulldozer.cpp:55:3: note: in expansion of macro 'rep'
   55 |   rep(i, V.size()) {
      |   ^~~
bulldozer.cpp:57:12: warning: comparison of integer expressions of different signedness: '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]
   57 |     while(l<V.size() && ilo(V[l].st, V[i].st)==0) {
      |           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 529 ms 67752 KB Output is correct
34 Correct 526 ms 66636 KB Output is correct
35 Correct 526 ms 68280 KB Output is correct
36 Correct 517 ms 66488 KB Output is correct
37 Correct 533 ms 68036 KB Output is correct
38 Correct 491 ms 66744 KB Output is correct
39 Correct 518 ms 67268 KB Output is correct
40 Correct 529 ms 66752 KB Output is correct
41 Correct 518 ms 66996 KB Output is correct
42 Correct 520 ms 66488 KB Output is correct
43 Correct 524 ms 67768 KB Output is correct
44 Correct 499 ms 66500 KB Output is correct
45 Correct 512 ms 66488 KB Output is correct
46 Correct 516 ms 66492 KB Output is correct
47 Correct 514 ms 66756 KB Output is correct
48 Correct 511 ms 66488 KB Output is correct
49 Correct 507 ms 68336 KB Output is correct
50 Correct 507 ms 68028 KB Output is correct
51 Correct 519 ms 67492 KB Output is correct
52 Correct 505 ms 68020 KB Output is correct
53 Correct 509 ms 67508 KB Output is correct
54 Correct 529 ms 66488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 529 ms 67752 KB Output is correct
34 Correct 526 ms 66636 KB Output is correct
35 Correct 526 ms 68280 KB Output is correct
36 Correct 517 ms 66488 KB Output is correct
37 Correct 533 ms 68036 KB Output is correct
38 Correct 491 ms 66744 KB Output is correct
39 Correct 518 ms 67268 KB Output is correct
40 Correct 529 ms 66752 KB Output is correct
41 Correct 518 ms 66996 KB Output is correct
42 Correct 520 ms 66488 KB Output is correct
43 Correct 524 ms 67768 KB Output is correct
44 Correct 499 ms 66500 KB Output is correct
45 Correct 512 ms 66488 KB Output is correct
46 Correct 516 ms 66492 KB Output is correct
47 Correct 514 ms 66756 KB Output is correct
48 Correct 511 ms 66488 KB Output is correct
49 Correct 507 ms 68336 KB Output is correct
50 Correct 507 ms 68028 KB Output is correct
51 Correct 519 ms 67492 KB Output is correct
52 Correct 505 ms 68020 KB Output is correct
53 Correct 509 ms 67508 KB Output is correct
54 Correct 529 ms 66488 KB Output is correct
55 Correct 531 ms 66748 KB Output is correct
56 Correct 525 ms 67008 KB Output is correct
57 Correct 523 ms 66332 KB Output is correct
58 Correct 533 ms 68292 KB Output is correct
59 Correct 522 ms 67256 KB Output is correct
60 Correct 510 ms 66748 KB Output is correct
61 Correct 497 ms 67268 KB Output is correct
62 Correct 498 ms 67244 KB Output is correct
63 Correct 501 ms 66232 KB Output is correct
64 Correct 516 ms 67256 KB Output is correct
65 Correct 512 ms 68288 KB Output is correct
66 Correct 528 ms 66744 KB Output is correct
67 Correct 520 ms 68036 KB Output is correct
68 Correct 518 ms 67268 KB Output is correct
69 Correct 529 ms 67776 KB Output is correct
70 Correct 510 ms 67264 KB Output is correct
71 Correct 513 ms 67512 KB Output is correct
72 Correct 528 ms 66740 KB Output is correct
73 Correct 499 ms 67008 KB Output is correct
74 Correct 523 ms 66992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 0 ms 464 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 460 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 1 ms 856 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 529 ms 67752 KB Output is correct
49 Correct 526 ms 66636 KB Output is correct
50 Correct 526 ms 68280 KB Output is correct
51 Correct 517 ms 66488 KB Output is correct
52 Correct 533 ms 68036 KB Output is correct
53 Correct 491 ms 66744 KB Output is correct
54 Correct 518 ms 67268 KB Output is correct
55 Correct 529 ms 66752 KB Output is correct
56 Correct 518 ms 66996 KB Output is correct
57 Correct 520 ms 66488 KB Output is correct
58 Correct 524 ms 67768 KB Output is correct
59 Correct 499 ms 66500 KB Output is correct
60 Correct 512 ms 66488 KB Output is correct
61 Correct 516 ms 66492 KB Output is correct
62 Correct 514 ms 66756 KB Output is correct
63 Correct 511 ms 66488 KB Output is correct
64 Correct 507 ms 68336 KB Output is correct
65 Correct 507 ms 68028 KB Output is correct
66 Correct 519 ms 67492 KB Output is correct
67 Correct 505 ms 68020 KB Output is correct
68 Correct 509 ms 67508 KB Output is correct
69 Correct 529 ms 66488 KB Output is correct
70 Correct 531 ms 66748 KB Output is correct
71 Correct 525 ms 67008 KB Output is correct
72 Correct 523 ms 66332 KB Output is correct
73 Correct 533 ms 68292 KB Output is correct
74 Correct 522 ms 67256 KB Output is correct
75 Correct 510 ms 66748 KB Output is correct
76 Correct 497 ms 67268 KB Output is correct
77 Correct 498 ms 67244 KB Output is correct
78 Correct 501 ms 66232 KB Output is correct
79 Correct 516 ms 67256 KB Output is correct
80 Correct 512 ms 68288 KB Output is correct
81 Correct 528 ms 66744 KB Output is correct
82 Correct 520 ms 68036 KB Output is correct
83 Correct 518 ms 67268 KB Output is correct
84 Correct 529 ms 67776 KB Output is correct
85 Correct 510 ms 67264 KB Output is correct
86 Correct 513 ms 67512 KB Output is correct
87 Correct 528 ms 66740 KB Output is correct
88 Correct 499 ms 67008 KB Output is correct
89 Correct 523 ms 66992 KB Output is correct
90 Correct 513 ms 67748 KB Output is correct
91 Correct 554 ms 68036 KB Output is correct
92 Correct 514 ms 67520 KB Output is correct
93 Correct 498 ms 66748 KB Output is correct
94 Correct 498 ms 68292 KB Output is correct
95 Correct 516 ms 67268 KB Output is correct
96 Correct 485 ms 68036 KB Output is correct
97 Correct 481 ms 66240 KB Output is correct
98 Correct 510 ms 66496 KB Output is correct
99 Correct 483 ms 66756 KB Output is correct
100 Correct 457 ms 66440 KB Output is correct
101 Correct 493 ms 68032 KB Output is correct
102 Correct 490 ms 66756 KB Output is correct
103 Correct 493 ms 67368 KB Output is correct
104 Correct 425 ms 67520 KB Output is correct
105 Correct 470 ms 67000 KB Output is correct
106 Correct 484 ms 66708 KB Output is correct
107 Correct 487 ms 67012 KB Output is correct
108 Correct 514 ms 67000 KB Output is correct
109 Correct 487 ms 66592 KB Output is correct
110 Correct 495 ms 67264 KB Output is correct
111 Correct 509 ms 66244 KB Output is correct
112 Correct 491 ms 67256 KB Output is correct
113 Correct 488 ms 66756 KB Output is correct
114 Correct 493 ms 68036 KB Output is correct
115 Correct 497 ms 67772 KB Output is correct
116 Correct 505 ms 67772 KB Output is correct
117 Correct 505 ms 67768 KB Output is correct
118 Correct 475 ms 68036 KB Output is correct
119 Correct 493 ms 67776 KB Output is correct
120 Correct 0 ms 344 KB Output is correct
121 Correct 0 ms 344 KB Output is correct
122 Correct 521 ms 68036 KB Output is correct
123 Correct 489 ms 67512 KB Output is correct
124 Correct 496 ms 67248 KB Output is correct
125 Correct 508 ms 67248 KB Output is correct
126 Correct 488 ms 67772 KB Output is correct
127 Correct 504 ms 66752 KB Output is correct
128 Correct 484 ms 67516 KB Output is correct
129 Correct 506 ms 67784 KB Output is correct
130 Correct 530 ms 68284 KB Output is correct
131 Correct 489 ms 66752 KB Output is correct
132 Correct 506 ms 66996 KB Output is correct
133 Correct 517 ms 67516 KB Output is correct