Submission #32623

# Submission time Handle Problem Language Result Execution time Memory
32623 2017-10-12T18:16:34 Z aome Bulldozer (JOI17_bulldozer) C++14
100 / 100
996 ms 32352 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
 
const int N = 2005;
const int INF = 1e9;
 
struct Point {
	int x, y, w;
} a[N];
 
struct Node {
	long long s, sl, sr, mx;
 
	Node () { s = sl = sr = 0, mx = -INF; }
};

typedef pair<int, int> ii;
 
int n, pos[N];
long long res;
Node it[4 * N];
vector<ii> go;
 
Node Merge(Node x, Node y) {
	Node z;
	z.s = x.s + y.s;
	z.sl = max(x.sl, x.s + y.sl);
	z.sr = max(x.sr + y.s, y.sr);
	z.mx = max(max(x.mx, y.mx), x.sr + y.sl);
	return z;
}
 
void build(int i, int l, int r) {
	if (l == r) {
		it[i].s = it[i].sl = it[i].sr = it[i].mx = a[l].w; return;
	}
	int mid = (l + r) >> 1;
	build(i << 1, l, mid), build(i << 1 | 1, mid + 1, r);
	it[i] = Merge(it[i << 1], it[i << 1 | 1]);
}
 
void upd(int i, int l, int r, int p, int v) {
	if (l == r) {
		it[i].s = it[i].sl = it[i].sr = it[i].mx = v; return;
	}
	int mid = (l + r) >> 1;
	if (p <= mid) upd(i << 1, l, mid, p, v);
	else upd(i << 1 | 1, mid + 1, r, p, v);
	it[i] = Merge(it[i << 1], it[i << 1 | 1]);
}

long long cal(ii x, ii y) {
	return 1LL * (a[x.fi].y - a[x.se].y) * (a[y.fi].x - a[y.se].x) - 1LL * (a[y.fi].y - a[y.se].y) * (a[x.fi].x - a[x.se].x);
}
 
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].x >> a[i].y >> a[i].w;
	}
	sort(a, a + n, [&](Point x, Point y) {
		return make_pair(x.y, x.x) < make_pair(y.y, y.x);
	});
	// for (int i = 0; i < n; ++i) {
	// 	cout << a[i].x << ' ' << a[i].y << ' ' << a[i].w << '\n';
	// }
	for (int i = 0; i < n; ++i) pos[i] = i;
	build(1, 0, n - 1);
	res = max(res, it[1].mx);
	for (int  i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			go.push_back(ii(i, j));
		}
	}
	sort(go.begin(), go.end(), [&](ii x, ii y) {
		long long tmp = cal(x, y);
		return tmp == 0 ? x < y : tmp < 0;
	});
	// for (auto i : go) cout << i.fi << ' ' << i.se << '\n';
	for (int i = 0; i < go.size(); ++i) {
		vector<ii> _go;
		_go.push_back(go[i]);
		while (i + 1 < go.size() && !cal(go[i], go[i + 1])) {
			i++, _go.push_back(go[i]);
		}
		for (auto j : _go) {
			// cout << j.x << ' ' << j.y << '\n';
			swap(pos[j.fi], pos[j.se]);
			upd(1, 0, n - 1, pos[j.fi], a[j.fi].w);
			upd(1, 0, n - 1, pos[j.se], a[j.se].w);
		}
		// for (int j = 0; j < n; ++j) cout << pos[j] << ' '; cout << '\n';
		res = max(res, it[1].mx);
	}
	cout << res << '\n';
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:83:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < go.size(); ++i) {
                  ~~^~~~~~~~~~~
bulldozer.cpp:86:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (i + 1 < go.size() && !cal(go[i], go[i + 1])) {
          ~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 784 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 556 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 556 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 870 ms 17132 KB Output is correct
34 Correct 862 ms 17132 KB Output is correct
35 Correct 892 ms 17124 KB Output is correct
36 Correct 852 ms 17120 KB Output is correct
37 Correct 863 ms 17132 KB Output is correct
38 Correct 896 ms 17132 KB Output is correct
39 Correct 885 ms 17120 KB Output is correct
40 Correct 918 ms 17132 KB Output is correct
41 Correct 848 ms 17216 KB Output is correct
42 Correct 856 ms 17252 KB Output is correct
43 Correct 856 ms 17224 KB Output is correct
44 Correct 840 ms 17132 KB Output is correct
45 Correct 848 ms 17148 KB Output is correct
46 Correct 834 ms 17252 KB Output is correct
47 Correct 865 ms 17132 KB Output is correct
48 Correct 925 ms 17132 KB Output is correct
49 Correct 876 ms 17132 KB Output is correct
50 Correct 938 ms 17132 KB Output is correct
51 Correct 887 ms 17124 KB Output is correct
52 Correct 880 ms 17200 KB Output is correct
53 Correct 870 ms 17260 KB Output is correct
54 Correct 850 ms 17120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 556 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 3 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 870 ms 17132 KB Output is correct
34 Correct 862 ms 17132 KB Output is correct
35 Correct 892 ms 17124 KB Output is correct
36 Correct 852 ms 17120 KB Output is correct
37 Correct 863 ms 17132 KB Output is correct
38 Correct 896 ms 17132 KB Output is correct
39 Correct 885 ms 17120 KB Output is correct
40 Correct 918 ms 17132 KB Output is correct
41 Correct 848 ms 17216 KB Output is correct
42 Correct 856 ms 17252 KB Output is correct
43 Correct 856 ms 17224 KB Output is correct
44 Correct 840 ms 17132 KB Output is correct
45 Correct 848 ms 17148 KB Output is correct
46 Correct 834 ms 17252 KB Output is correct
47 Correct 865 ms 17132 KB Output is correct
48 Correct 925 ms 17132 KB Output is correct
49 Correct 876 ms 17132 KB Output is correct
50 Correct 938 ms 17132 KB Output is correct
51 Correct 887 ms 17124 KB Output is correct
52 Correct 880 ms 17200 KB Output is correct
53 Correct 870 ms 17260 KB Output is correct
54 Correct 850 ms 17120 KB Output is correct
55 Correct 851 ms 17124 KB Output is correct
56 Correct 845 ms 17132 KB Output is correct
57 Correct 863 ms 17252 KB Output is correct
58 Correct 870 ms 17316 KB Output is correct
59 Correct 869 ms 17132 KB Output is correct
60 Correct 885 ms 17132 KB Output is correct
61 Correct 880 ms 17220 KB Output is correct
62 Correct 850 ms 17132 KB Output is correct
63 Correct 889 ms 17124 KB Output is correct
64 Correct 912 ms 17120 KB Output is correct
65 Correct 885 ms 17124 KB Output is correct
66 Correct 869 ms 17132 KB Output is correct
67 Correct 861 ms 17116 KB Output is correct
68 Correct 893 ms 17120 KB Output is correct
69 Correct 896 ms 17128 KB Output is correct
70 Correct 865 ms 17216 KB Output is correct
71 Correct 849 ms 17124 KB Output is correct
72 Correct 850 ms 17132 KB Output is correct
73 Correct 870 ms 17132 KB Output is correct
74 Correct 869 ms 17220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 784 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 4 ms 640 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 2 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 2 ms 640 KB Output is correct
30 Correct 2 ms 556 KB Output is correct
31 Correct 2 ms 560 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 4 ms 768 KB Output is correct
37 Correct 4 ms 640 KB Output is correct
38 Correct 4 ms 640 KB Output is correct
39 Correct 4 ms 640 KB Output is correct
40 Correct 4 ms 768 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 4 ms 640 KB Output is correct
43 Correct 4 ms 640 KB Output is correct
44 Correct 4 ms 640 KB Output is correct
45 Correct 4 ms 640 KB Output is correct
46 Correct 3 ms 640 KB Output is correct
47 Correct 4 ms 640 KB Output is correct
48 Correct 870 ms 17132 KB Output is correct
49 Correct 862 ms 17132 KB Output is correct
50 Correct 892 ms 17124 KB Output is correct
51 Correct 852 ms 17120 KB Output is correct
52 Correct 863 ms 17132 KB Output is correct
53 Correct 896 ms 17132 KB Output is correct
54 Correct 885 ms 17120 KB Output is correct
55 Correct 918 ms 17132 KB Output is correct
56 Correct 848 ms 17216 KB Output is correct
57 Correct 856 ms 17252 KB Output is correct
58 Correct 856 ms 17224 KB Output is correct
59 Correct 840 ms 17132 KB Output is correct
60 Correct 848 ms 17148 KB Output is correct
61 Correct 834 ms 17252 KB Output is correct
62 Correct 865 ms 17132 KB Output is correct
63 Correct 925 ms 17132 KB Output is correct
64 Correct 876 ms 17132 KB Output is correct
65 Correct 938 ms 17132 KB Output is correct
66 Correct 887 ms 17124 KB Output is correct
67 Correct 880 ms 17200 KB Output is correct
68 Correct 870 ms 17260 KB Output is correct
69 Correct 850 ms 17120 KB Output is correct
70 Correct 851 ms 17124 KB Output is correct
71 Correct 845 ms 17132 KB Output is correct
72 Correct 863 ms 17252 KB Output is correct
73 Correct 870 ms 17316 KB Output is correct
74 Correct 869 ms 17132 KB Output is correct
75 Correct 885 ms 17132 KB Output is correct
76 Correct 880 ms 17220 KB Output is correct
77 Correct 850 ms 17132 KB Output is correct
78 Correct 889 ms 17124 KB Output is correct
79 Correct 912 ms 17120 KB Output is correct
80 Correct 885 ms 17124 KB Output is correct
81 Correct 869 ms 17132 KB Output is correct
82 Correct 861 ms 17116 KB Output is correct
83 Correct 893 ms 17120 KB Output is correct
84 Correct 896 ms 17128 KB Output is correct
85 Correct 865 ms 17216 KB Output is correct
86 Correct 849 ms 17124 KB Output is correct
87 Correct 850 ms 17132 KB Output is correct
88 Correct 870 ms 17132 KB Output is correct
89 Correct 869 ms 17220 KB Output is correct
90 Correct 926 ms 17136 KB Output is correct
91 Correct 864 ms 17240 KB Output is correct
92 Correct 850 ms 17224 KB Output is correct
93 Correct 853 ms 17132 KB Output is correct
94 Correct 873 ms 17192 KB Output is correct
95 Correct 885 ms 17232 KB Output is correct
96 Correct 884 ms 17312 KB Output is correct
97 Correct 880 ms 17120 KB Output is correct
98 Correct 860 ms 17132 KB Output is correct
99 Correct 855 ms 17120 KB Output is correct
100 Correct 762 ms 32332 KB Output is correct
101 Correct 737 ms 32328 KB Output is correct
102 Correct 763 ms 32324 KB Output is correct
103 Correct 717 ms 32320 KB Output is correct
104 Correct 723 ms 32352 KB Output is correct
105 Correct 778 ms 29668 KB Output is correct
106 Correct 777 ms 29760 KB Output is correct
107 Correct 766 ms 29632 KB Output is correct
108 Correct 810 ms 29752 KB Output is correct
109 Correct 783 ms 29756 KB Output is correct
110 Correct 736 ms 17124 KB Output is correct
111 Correct 735 ms 17132 KB Output is correct
112 Correct 746 ms 17124 KB Output is correct
113 Correct 761 ms 17216 KB Output is correct
114 Correct 747 ms 17124 KB Output is correct
115 Correct 778 ms 17148 KB Output is correct
116 Correct 759 ms 17132 KB Output is correct
117 Correct 777 ms 17132 KB Output is correct
118 Correct 776 ms 17132 KB Output is correct
119 Correct 737 ms 17168 KB Output is correct
120 Correct 2 ms 640 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Correct 874 ms 17132 KB Output is correct
123 Correct 945 ms 17132 KB Output is correct
124 Correct 852 ms 17204 KB Output is correct
125 Correct 870 ms 17164 KB Output is correct
126 Correct 857 ms 17176 KB Output is correct
127 Correct 881 ms 17116 KB Output is correct
128 Correct 891 ms 17260 KB Output is correct
129 Correct 996 ms 17132 KB Output is correct
130 Correct 889 ms 17216 KB Output is correct
131 Correct 917 ms 17132 KB Output is correct
132 Correct 888 ms 17124 KB Output is correct
133 Correct 890 ms 17224 KB Output is correct