Submission #270451

# Submission time Handle Problem Language Result Execution time Memory
270451 2020-08-17T15:47:33 Z cgiosy Bulldozer (JOI17_bulldozer) C++17
80 / 100
595 ms 31996 KB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

struct node {
	ll mx, lm, rm, sum;
	node operator+(const node R) const {
		return {
			max({mx, R.mx, rm+R.lm}),
			max(lm, sum+R.lm),
			max(R.rm, rm+R.sum),
			sum+R.sum
		};
	}
};
struct point { int x, y; };
struct event {
	int x, y, i, j;
	bool operator<(const event& R) const {
		return ll(x)*R.y<ll(y)*R.x;
	}
};
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int N;
	cin>>N;
	const int M=1<<32-__builtin_clz(N), K=N*(N-1)/2;
	vector<point> A(N);
	vector<int> W(N), P(N), X(N);
	for(int i=0; i<N; i++)
		cin>>A[i].x>>A[i].y>>W[i];
	iota(begin(X), end(X), 0);
	sort(begin(X), end(X), [&](int i, int j) {
		return A[i].x<A[j].x || A[i].x==A[j].x && A[i].y<A[j].y;
	});
	for(int i=0; i<N; i++) P[X[i]]=i;
	decltype(X)().swap(X);

	vector<event> E(K);
	for(int i=0, k=0; i<N; i++) for(int j=0; j<i; j++) {
		int x=A[i].x-A[j].x, y=A[i].y-A[j].y;
		if(x<0 || !x && y<0) x=-x, y=-y;
		E[k++]={x, y, i, j};
	}
	sort(begin(E), end(E));

	vector<node> T(M*2);
	auto upd=[&](int i, int x) {
		for(T[i+=M]={x, x, x, x}; i>>=1;)
			T[i]=T[i*2]+T[i*2+1];
	};
	for(int i=0; i<N; i++) {
		int x=W[i];
		T[P[i]+M]={x, x, x, x};
	}
	for(int i=M; i--;)
		T[i]=T[i*2]+T[i*2+1];

	ll mx=T[1].mx;
	for(int k=0; k<K; k++) {
		auto[x,y,i,j]=E[k];
		swap(P[i], P[j]);
		upd(P[i], W[i]);
		upd(P[j], W[j]);
		if(k+1==K || !(E[k]<E[k+1])) continue;
		mx=max(mx, T[1].mx);
	}
	cout<<max(mx, ll(0))<<'\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:27:19: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   27 |  const int M=1<<32-__builtin_clz(N), K=N*(N-1)/2;
      |                 ~~^~~~~~~~~~~~~~~~~
bulldozer.cpp: In lambda function:
bulldozer.cpp:34:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   34 |   return A[i].x<A[j].x || A[i].x==A[j].x && A[i].y<A[j].y;
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:42:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   42 |   if(x<0 || !x && y<0) x=-x, y=-y;
      |             ~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 416 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 416 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 544 ms 31992 KB Output is correct
34 Correct 548 ms 31860 KB Output is correct
35 Correct 542 ms 31864 KB Output is correct
36 Correct 582 ms 31864 KB Output is correct
37 Correct 584 ms 31864 KB Output is correct
38 Correct 557 ms 31864 KB Output is correct
39 Correct 573 ms 31736 KB Output is correct
40 Correct 561 ms 31736 KB Output is correct
41 Correct 546 ms 31736 KB Output is correct
42 Correct 541 ms 31864 KB Output is correct
43 Correct 548 ms 31864 KB Output is correct
44 Correct 566 ms 31864 KB Output is correct
45 Correct 536 ms 31736 KB Output is correct
46 Correct 540 ms 31896 KB Output is correct
47 Correct 536 ms 31864 KB Output is correct
48 Correct 548 ms 31868 KB Output is correct
49 Correct 538 ms 31992 KB Output is correct
50 Correct 543 ms 31864 KB Output is correct
51 Correct 576 ms 31736 KB Output is correct
52 Correct 586 ms 31736 KB Output is correct
53 Correct 549 ms 31860 KB Output is correct
54 Correct 552 ms 31864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 416 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 544 ms 31992 KB Output is correct
34 Correct 548 ms 31860 KB Output is correct
35 Correct 542 ms 31864 KB Output is correct
36 Correct 582 ms 31864 KB Output is correct
37 Correct 584 ms 31864 KB Output is correct
38 Correct 557 ms 31864 KB Output is correct
39 Correct 573 ms 31736 KB Output is correct
40 Correct 561 ms 31736 KB Output is correct
41 Correct 546 ms 31736 KB Output is correct
42 Correct 541 ms 31864 KB Output is correct
43 Correct 548 ms 31864 KB Output is correct
44 Correct 566 ms 31864 KB Output is correct
45 Correct 536 ms 31736 KB Output is correct
46 Correct 540 ms 31896 KB Output is correct
47 Correct 536 ms 31864 KB Output is correct
48 Correct 548 ms 31868 KB Output is correct
49 Correct 538 ms 31992 KB Output is correct
50 Correct 543 ms 31864 KB Output is correct
51 Correct 576 ms 31736 KB Output is correct
52 Correct 586 ms 31736 KB Output is correct
53 Correct 549 ms 31860 KB Output is correct
54 Correct 552 ms 31864 KB Output is correct
55 Correct 534 ms 31864 KB Output is correct
56 Correct 541 ms 31736 KB Output is correct
57 Correct 542 ms 31864 KB Output is correct
58 Correct 542 ms 31864 KB Output is correct
59 Correct 539 ms 31864 KB Output is correct
60 Correct 540 ms 31736 KB Output is correct
61 Correct 541 ms 31740 KB Output is correct
62 Correct 542 ms 31864 KB Output is correct
63 Correct 595 ms 31864 KB Output is correct
64 Correct 550 ms 31868 KB Output is correct
65 Correct 566 ms 31864 KB Output is correct
66 Correct 568 ms 31988 KB Output is correct
67 Correct 563 ms 31992 KB Output is correct
68 Correct 541 ms 31864 KB Output is correct
69 Correct 542 ms 31864 KB Output is correct
70 Correct 577 ms 31864 KB Output is correct
71 Correct 560 ms 31864 KB Output is correct
72 Correct 540 ms 31860 KB Output is correct
73 Correct 566 ms 31996 KB Output is correct
74 Correct 551 ms 31864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 416 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 544 ms 31992 KB Output is correct
49 Correct 548 ms 31860 KB Output is correct
50 Correct 542 ms 31864 KB Output is correct
51 Correct 582 ms 31864 KB Output is correct
52 Correct 584 ms 31864 KB Output is correct
53 Correct 557 ms 31864 KB Output is correct
54 Correct 573 ms 31736 KB Output is correct
55 Correct 561 ms 31736 KB Output is correct
56 Correct 546 ms 31736 KB Output is correct
57 Correct 541 ms 31864 KB Output is correct
58 Correct 548 ms 31864 KB Output is correct
59 Correct 566 ms 31864 KB Output is correct
60 Correct 536 ms 31736 KB Output is correct
61 Correct 540 ms 31896 KB Output is correct
62 Correct 536 ms 31864 KB Output is correct
63 Correct 548 ms 31868 KB Output is correct
64 Correct 538 ms 31992 KB Output is correct
65 Correct 543 ms 31864 KB Output is correct
66 Correct 576 ms 31736 KB Output is correct
67 Correct 586 ms 31736 KB Output is correct
68 Correct 549 ms 31860 KB Output is correct
69 Correct 552 ms 31864 KB Output is correct
70 Correct 534 ms 31864 KB Output is correct
71 Correct 541 ms 31736 KB Output is correct
72 Correct 542 ms 31864 KB Output is correct
73 Correct 542 ms 31864 KB Output is correct
74 Correct 539 ms 31864 KB Output is correct
75 Correct 540 ms 31736 KB Output is correct
76 Correct 541 ms 31740 KB Output is correct
77 Correct 542 ms 31864 KB Output is correct
78 Correct 595 ms 31864 KB Output is correct
79 Correct 550 ms 31868 KB Output is correct
80 Correct 566 ms 31864 KB Output is correct
81 Correct 568 ms 31988 KB Output is correct
82 Correct 563 ms 31992 KB Output is correct
83 Correct 541 ms 31864 KB Output is correct
84 Correct 542 ms 31864 KB Output is correct
85 Correct 577 ms 31864 KB Output is correct
86 Correct 560 ms 31864 KB Output is correct
87 Correct 540 ms 31860 KB Output is correct
88 Correct 566 ms 31996 KB Output is correct
89 Correct 551 ms 31864 KB Output is correct
90 Correct 561 ms 31864 KB Output is correct
91 Correct 550 ms 31992 KB Output is correct
92 Correct 544 ms 31988 KB Output is correct
93 Correct 563 ms 31864 KB Output is correct
94 Correct 554 ms 31868 KB Output is correct
95 Correct 559 ms 31988 KB Output is correct
96 Correct 542 ms 31864 KB Output is correct
97 Correct 546 ms 31864 KB Output is correct
98 Correct 550 ms 31988 KB Output is correct
99 Correct 550 ms 31736 KB Output is correct
100 Incorrect 460 ms 31992 KB Output isn't correct
101 Halted 0 ms 0 KB -