Submission #309261

# Submission time Handle Problem Language Result Execution time Memory
309261 2020-10-03T03:09:31 Z cgiosy Bulldozer (JOI17_bulldozer) C++17
100 / 100
852 ms 8564 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define R(i,n,...) for(int i=__VA_ARGS__+0; i<n; i++)
using namespace std;

struct node {
	long 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 pii {
	int x, y;
	bool operator<(pii b) const { return x<b.x || x==b.x && y<b.y; }
	pii operator-(pii b) const { return {x-b.x, y-b.y}; }
	long operator^(pii b) const { return 1LL*x*b.y-1LL*y*b.x; }
};
struct iii {
	pii p; int w;
	bool operator<(const iii& b) const { return p<b.p; }
};

union evt {
	struct { unsigned short i, j; };
	unsigned int k;
};

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int N, K=0;
	cin>>N;
	iii A[N];
	int P[N];
	R(i, N) cin>>A[i].p.x>>A[i].p.y>>A[i].w;
	sort(A, A+N);
	iota(P, P+N, 0);

	evt E[N*(N-1)/2];
	R(i, N) R(j, i) E[K].i=i, E[K++].j=j;
	sort(E, E+K, [&](evt l, evt r) {
		auto x=A[l.i].p-A[l.j].p^A[r.i].p-A[r.j].p;
		return x<0 || !x && l.k<r.k;
	});

	node T[4096]{};
	auto upd=[&](int i, int x) {
		for(T[i|=2048]={x, x, x, x}; i>>=1;)
			T[i]=T[i*2]+T[i*2+1];
	};
	for(int i=N; i--;) {
		int w=A[i].w;
		T[i+2048]={w, w, w, w};
	}
	for(int i=2048; --i;)
		T[i]=T[i*2]+T[i*2+1];

	long mx=T[1].mx;
	for(int k=0; k<K; k++) {
		int i=E[k].i, j=E[k].j;
		swap(P[i], P[j]);
		upd(P[i], A[i].w);
		upd(P[j], A[j].w);
		if(k+1<K && !(A[i].p-A[j].p^A[E[k+1].i].p-A[E[k+1].j].p)) continue;
		mx=max(mx, T[1].mx);
	}
	cout<<mx;
}

Compilation message

bulldozer.cpp: In member function 'bool pii::operator<(pii) const':
bulldozer.cpp:19:55: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |  bool operator<(pii b) const { return x<b.x || x==b.x && y<b.y; }
      |                                                ~~~~~~~^~~~~~~~
bulldozer.cpp: In lambda function:
bulldozer.cpp:46:18: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   46 |   auto x=A[l.i].p-A[l.j].p^A[r.i].p-A[r.j].p;
      |          ~~~~~~~~^~~~~~~~~
bulldozer.cpp:47:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   47 |   return x<0 || !x && l.k<r.k;
      |                 ~~~^~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:68:23: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   68 |   if(k+1<K && !(A[i].p-A[j].p^A[E[k+1].i].p-A[E[k+1].j].p)) continue;
      |                 ~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 416 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 416 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 845 ms 8312 KB Output is correct
34 Correct 822 ms 8312 KB Output is correct
35 Correct 821 ms 8440 KB Output is correct
36 Correct 809 ms 8440 KB Output is correct
37 Correct 824 ms 8316 KB Output is correct
38 Correct 816 ms 8312 KB Output is correct
39 Correct 822 ms 8440 KB Output is correct
40 Correct 813 ms 8440 KB Output is correct
41 Correct 825 ms 8432 KB Output is correct
42 Correct 836 ms 8312 KB Output is correct
43 Correct 835 ms 8432 KB Output is correct
44 Correct 803 ms 8440 KB Output is correct
45 Correct 799 ms 8440 KB Output is correct
46 Correct 828 ms 8312 KB Output is correct
47 Correct 818 ms 8312 KB Output is correct
48 Correct 803 ms 8440 KB Output is correct
49 Correct 806 ms 8440 KB Output is correct
50 Correct 815 ms 8316 KB Output is correct
51 Correct 816 ms 8312 KB Output is correct
52 Correct 843 ms 8460 KB Output is correct
53 Correct 822 ms 8560 KB Output is correct
54 Correct 820 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 416 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 845 ms 8312 KB Output is correct
34 Correct 822 ms 8312 KB Output is correct
35 Correct 821 ms 8440 KB Output is correct
36 Correct 809 ms 8440 KB Output is correct
37 Correct 824 ms 8316 KB Output is correct
38 Correct 816 ms 8312 KB Output is correct
39 Correct 822 ms 8440 KB Output is correct
40 Correct 813 ms 8440 KB Output is correct
41 Correct 825 ms 8432 KB Output is correct
42 Correct 836 ms 8312 KB Output is correct
43 Correct 835 ms 8432 KB Output is correct
44 Correct 803 ms 8440 KB Output is correct
45 Correct 799 ms 8440 KB Output is correct
46 Correct 828 ms 8312 KB Output is correct
47 Correct 818 ms 8312 KB Output is correct
48 Correct 803 ms 8440 KB Output is correct
49 Correct 806 ms 8440 KB Output is correct
50 Correct 815 ms 8316 KB Output is correct
51 Correct 816 ms 8312 KB Output is correct
52 Correct 843 ms 8460 KB Output is correct
53 Correct 822 ms 8560 KB Output is correct
54 Correct 820 ms 8440 KB Output is correct
55 Correct 836 ms 8436 KB Output is correct
56 Correct 811 ms 8440 KB Output is correct
57 Correct 830 ms 8440 KB Output is correct
58 Correct 817 ms 8552 KB Output is correct
59 Correct 817 ms 8440 KB Output is correct
60 Correct 820 ms 8440 KB Output is correct
61 Correct 820 ms 8440 KB Output is correct
62 Correct 837 ms 8312 KB Output is correct
63 Correct 822 ms 8432 KB Output is correct
64 Correct 826 ms 8444 KB Output is correct
65 Correct 827 ms 8440 KB Output is correct
66 Correct 816 ms 8440 KB Output is correct
67 Correct 821 ms 8312 KB Output is correct
68 Correct 840 ms 8436 KB Output is correct
69 Correct 810 ms 8312 KB Output is correct
70 Correct 821 ms 8440 KB Output is correct
71 Correct 809 ms 8440 KB Output is correct
72 Correct 831 ms 8564 KB Output is correct
73 Correct 828 ms 8440 KB Output is correct
74 Correct 819 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 416 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 2 ms 512 KB Output is correct
48 Correct 845 ms 8312 KB Output is correct
49 Correct 822 ms 8312 KB Output is correct
50 Correct 821 ms 8440 KB Output is correct
51 Correct 809 ms 8440 KB Output is correct
52 Correct 824 ms 8316 KB Output is correct
53 Correct 816 ms 8312 KB Output is correct
54 Correct 822 ms 8440 KB Output is correct
55 Correct 813 ms 8440 KB Output is correct
56 Correct 825 ms 8432 KB Output is correct
57 Correct 836 ms 8312 KB Output is correct
58 Correct 835 ms 8432 KB Output is correct
59 Correct 803 ms 8440 KB Output is correct
60 Correct 799 ms 8440 KB Output is correct
61 Correct 828 ms 8312 KB Output is correct
62 Correct 818 ms 8312 KB Output is correct
63 Correct 803 ms 8440 KB Output is correct
64 Correct 806 ms 8440 KB Output is correct
65 Correct 815 ms 8316 KB Output is correct
66 Correct 816 ms 8312 KB Output is correct
67 Correct 843 ms 8460 KB Output is correct
68 Correct 822 ms 8560 KB Output is correct
69 Correct 820 ms 8440 KB Output is correct
70 Correct 836 ms 8436 KB Output is correct
71 Correct 811 ms 8440 KB Output is correct
72 Correct 830 ms 8440 KB Output is correct
73 Correct 817 ms 8552 KB Output is correct
74 Correct 817 ms 8440 KB Output is correct
75 Correct 820 ms 8440 KB Output is correct
76 Correct 820 ms 8440 KB Output is correct
77 Correct 837 ms 8312 KB Output is correct
78 Correct 822 ms 8432 KB Output is correct
79 Correct 826 ms 8444 KB Output is correct
80 Correct 827 ms 8440 KB Output is correct
81 Correct 816 ms 8440 KB Output is correct
82 Correct 821 ms 8312 KB Output is correct
83 Correct 840 ms 8436 KB Output is correct
84 Correct 810 ms 8312 KB Output is correct
85 Correct 821 ms 8440 KB Output is correct
86 Correct 809 ms 8440 KB Output is correct
87 Correct 831 ms 8564 KB Output is correct
88 Correct 828 ms 8440 KB Output is correct
89 Correct 819 ms 8440 KB Output is correct
90 Correct 829 ms 8440 KB Output is correct
91 Correct 826 ms 8440 KB Output is correct
92 Correct 824 ms 8440 KB Output is correct
93 Correct 839 ms 8436 KB Output is correct
94 Correct 831 ms 8440 KB Output is correct
95 Correct 821 ms 8436 KB Output is correct
96 Correct 813 ms 8440 KB Output is correct
97 Correct 830 ms 8440 KB Output is correct
98 Correct 834 ms 8440 KB Output is correct
99 Correct 827 ms 8440 KB Output is correct
100 Correct 685 ms 8440 KB Output is correct
101 Correct 673 ms 8312 KB Output is correct
102 Correct 674 ms 8316 KB Output is correct
103 Correct 692 ms 8312 KB Output is correct
104 Correct 679 ms 8440 KB Output is correct
105 Correct 715 ms 8440 KB Output is correct
106 Correct 702 ms 8312 KB Output is correct
107 Correct 704 ms 8440 KB Output is correct
108 Correct 701 ms 8440 KB Output is correct
109 Correct 708 ms 8312 KB Output is correct
110 Correct 747 ms 8440 KB Output is correct
111 Correct 757 ms 8440 KB Output is correct
112 Correct 764 ms 8440 KB Output is correct
113 Correct 755 ms 8444 KB Output is correct
114 Correct 772 ms 8444 KB Output is correct
115 Correct 755 ms 8440 KB Output is correct
116 Correct 771 ms 8312 KB Output is correct
117 Correct 752 ms 8440 KB Output is correct
118 Correct 762 ms 8440 KB Output is correct
119 Correct 759 ms 8312 KB Output is correct
120 Correct 1 ms 512 KB Output is correct
121 Correct 1 ms 512 KB Output is correct
122 Correct 828 ms 8312 KB Output is correct
123 Correct 812 ms 8440 KB Output is correct
124 Correct 841 ms 8312 KB Output is correct
125 Correct 822 ms 8440 KB Output is correct
126 Correct 829 ms 8440 KB Output is correct
127 Correct 817 ms 8312 KB Output is correct
128 Correct 821 ms 8312 KB Output is correct
129 Correct 818 ms 8312 KB Output is correct
130 Correct 822 ms 8440 KB Output is correct
131 Correct 825 ms 8440 KB Output is correct
132 Correct 852 ms 8436 KB Output is correct
133 Correct 802 ms 8440 KB Output is correct