답안 #102721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102721 2019-03-27T08:31:03 Z Minnakhmetov Bulldozer (JOI17_bulldozer) C++14
100 / 100
1280 ms 16352 KB
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)

ll gcd(ll a, ll b) {
	return a ? gcd(b % a, a) : b;
}

struct P {
	ll x, y, w;
	ll operator * (const P &oth) const {
		return x * oth.y - y * oth.x;
	}
	ll operator / (const P &oth) const {
		return x * oth.x + y * oth.y;
	}
};

P operator - (const P &a, const P &b) {
	return { a.x - b.x, a.y - b.y };
}

const int N = 2005;
P a[N];
ll t[N * 4], mnp[N * 4], mxp[N * 4], pref[N], up[N * 4];
int pos[N];
int n;
pair<int, int> z[N * N];

void mrg(int v) {
	t[v] = max(t[v * 2], t[v * 2 + 1]);
	t[v] = max(t[v], mxp[v * 2 + 1] - mnp[v * 2]);
	mxp[v] = max(mxp[v * 2], mxp[v * 2 + 1]);
	mnp[v] = min(mnp[v * 2], mnp[v * 2 + 1]);
}

void build(int v = 1, int L = 0, int R = n) {
	if (L == R) {
		t[v] = 0;
		mxp[v] = mnp[v] = pref[L];
	}
	else {
		int m = (L + R) >> 1;
		build(v * 2, L, m);
		build(v * 2 + 1, m + 1, R);
		mrg(v);
	}
}

void push(int v, int L, int R) {
	if (up[v]) {
		if (L != R) {
			up[v * 2] += up[v];
			up[v * 2 + 1] += up[v];
		}
		mnp[v] += up[v];
		mxp[v] += up[v];
		up[v] = 0;
	}
}

void upd(int l, int r, int x, int v = 1, int L = 0, int R = n) {
	push(v, L, R);
	if (l > r)
		return;
	if (l == L && r == R) {
		up[v] += x;
		push(v, L, R);
	}
	else {
		int m = (L + R) >> 1;
		upd(l, min(m, r), x, v * 2, L, m);
		upd(max(m + 1, l), r, x, v * 2 + 1, m + 1, R);
		mrg(v);
	}
}


//void print() {
//	P tmp[N];
//	for (int i = 1; i <= n; i++)
//		tmp[pos[i]] = a[i];
//	for (int i = 1; i <= n; i++)
//		cout << tmp[i].x << " " << tmp[i].y << " " << tmp[i].w << "\n";
//	cout << "\n";
//}

signed main() {
#ifdef HOME
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		a[i] = { x, y, w };
	}

	sort(a + 1, a + n + 1, [](P &a, P &b) {
		return a.x == b.x ? a.y > b.y : a.x < b.x;
	});

	int ct = 0;
	for (int i = 1; i <= n; i++) {
		pos[i] = i;
		pref[i] = pref[i - 1] + a[i].w;
		for (int j = i + 1; j <= n; j++) {
			z[ct++] = { i, j };
		}
	}

	build();

	//print();

	sort(z, z + ct, [](pair<int, int> &p, pair<int, int> &q) {
		P vp = a[p.second] - a[p.first], vq = a[q.second] - a[q.first];
		if (vp.x > 0 || vp.x == 0 && vp.y < 0) {
			swap(p.first, p.second);
			vp.x = -vp.x;
			vp.y = -vp.y;
		}
		if (vq.x > 0 || vq.x == 0 && vq.y < 0) {
			swap(q.first, q.second);
			vq.x = -vq.x;
			vq.y = -vq.y;
		}
		ll prod = vp * vq;
		if (prod != 0)
			return prod > 0;
		prod = (a[p.second] - a[p.first]) / (a[q.first] - a[p.first]);
		if (prod != 0)
			return prod > 0;
		return abs(vp.x) < abs(vq.x) || abs(vp.y) < abs(vq.y);
	});;


	ll ans = t[1];

	for (int i = 0; i < ct; i++) {
		int x = z[i].first,
			y = z[i].second;
		if (pos[x] > pos[y]) {
			swap(x, y);
		}

		upd(pos[x], pos[y] - 1, -a[x].w);
		upd(pos[x], pos[y] - 1, a[y].w);

		swap(pos[x], pos[y]);

		if (i == ct - 1 || (a[z[i + 1].second] - a[z[i + 1].first]) *
			(a[y] - a[x]) != 0) {
			ans = max(ans, t[1]);
		}
	}

	cout << ans;

	return 0;
}

Compilation message

bulldozer.cpp:41:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
 
bulldozer.cpp: In lambda function:
bulldozer.cpp:161:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (vp.x > 0 || vp.x == 0 && vp.y < 0) {
                   ~~~~~~~~~~^~~~~~~~~~~
bulldozer.cpp:166:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (vq.x > 0 || vq.x == 0 && vq.y < 0) {
                   ~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 484 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 3 ms 396 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 476 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 3 ms 396 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 476 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1221 ms 16260 KB Output is correct
34 Correct 1187 ms 16252 KB Output is correct
35 Correct 1195 ms 16248 KB Output is correct
36 Correct 1187 ms 16252 KB Output is correct
37 Correct 1189 ms 16248 KB Output is correct
38 Correct 1175 ms 16256 KB Output is correct
39 Correct 1185 ms 16244 KB Output is correct
40 Correct 1205 ms 16248 KB Output is correct
41 Correct 1202 ms 16248 KB Output is correct
42 Correct 1189 ms 16216 KB Output is correct
43 Correct 1184 ms 16348 KB Output is correct
44 Correct 1190 ms 16352 KB Output is correct
45 Correct 1181 ms 16248 KB Output is correct
46 Correct 1195 ms 16244 KB Output is correct
47 Correct 1197 ms 16244 KB Output is correct
48 Correct 1202 ms 16252 KB Output is correct
49 Correct 1193 ms 16248 KB Output is correct
50 Correct 1252 ms 16240 KB Output is correct
51 Correct 1172 ms 16244 KB Output is correct
52 Correct 1206 ms 16252 KB Output is correct
53 Correct 1198 ms 16348 KB Output is correct
54 Correct 1203 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 3 ms 396 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 476 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1221 ms 16260 KB Output is correct
34 Correct 1187 ms 16252 KB Output is correct
35 Correct 1195 ms 16248 KB Output is correct
36 Correct 1187 ms 16252 KB Output is correct
37 Correct 1189 ms 16248 KB Output is correct
38 Correct 1175 ms 16256 KB Output is correct
39 Correct 1185 ms 16244 KB Output is correct
40 Correct 1205 ms 16248 KB Output is correct
41 Correct 1202 ms 16248 KB Output is correct
42 Correct 1189 ms 16216 KB Output is correct
43 Correct 1184 ms 16348 KB Output is correct
44 Correct 1190 ms 16352 KB Output is correct
45 Correct 1181 ms 16248 KB Output is correct
46 Correct 1195 ms 16244 KB Output is correct
47 Correct 1197 ms 16244 KB Output is correct
48 Correct 1202 ms 16252 KB Output is correct
49 Correct 1193 ms 16248 KB Output is correct
50 Correct 1252 ms 16240 KB Output is correct
51 Correct 1172 ms 16244 KB Output is correct
52 Correct 1206 ms 16252 KB Output is correct
53 Correct 1198 ms 16348 KB Output is correct
54 Correct 1203 ms 16220 KB Output is correct
55 Correct 1187 ms 16348 KB Output is correct
56 Correct 1192 ms 16256 KB Output is correct
57 Correct 1230 ms 16252 KB Output is correct
58 Correct 1201 ms 16248 KB Output is correct
59 Correct 1253 ms 16248 KB Output is correct
60 Correct 1195 ms 16248 KB Output is correct
61 Correct 1212 ms 16252 KB Output is correct
62 Correct 1202 ms 16220 KB Output is correct
63 Correct 1208 ms 16248 KB Output is correct
64 Correct 1201 ms 16344 KB Output is correct
65 Correct 1196 ms 16248 KB Output is correct
66 Correct 1193 ms 16352 KB Output is correct
67 Correct 1218 ms 16248 KB Output is correct
68 Correct 1188 ms 16312 KB Output is correct
69 Correct 1216 ms 16248 KB Output is correct
70 Correct 1200 ms 16348 KB Output is correct
71 Correct 1200 ms 16248 KB Output is correct
72 Correct 1217 ms 16248 KB Output is correct
73 Correct 1280 ms 16244 KB Output is correct
74 Correct 1217 ms 16256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 484 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 3 ms 396 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 4 ms 476 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 1221 ms 16260 KB Output is correct
49 Correct 1187 ms 16252 KB Output is correct
50 Correct 1195 ms 16248 KB Output is correct
51 Correct 1187 ms 16252 KB Output is correct
52 Correct 1189 ms 16248 KB Output is correct
53 Correct 1175 ms 16256 KB Output is correct
54 Correct 1185 ms 16244 KB Output is correct
55 Correct 1205 ms 16248 KB Output is correct
56 Correct 1202 ms 16248 KB Output is correct
57 Correct 1189 ms 16216 KB Output is correct
58 Correct 1184 ms 16348 KB Output is correct
59 Correct 1190 ms 16352 KB Output is correct
60 Correct 1181 ms 16248 KB Output is correct
61 Correct 1195 ms 16244 KB Output is correct
62 Correct 1197 ms 16244 KB Output is correct
63 Correct 1202 ms 16252 KB Output is correct
64 Correct 1193 ms 16248 KB Output is correct
65 Correct 1252 ms 16240 KB Output is correct
66 Correct 1172 ms 16244 KB Output is correct
67 Correct 1206 ms 16252 KB Output is correct
68 Correct 1198 ms 16348 KB Output is correct
69 Correct 1203 ms 16220 KB Output is correct
70 Correct 1187 ms 16348 KB Output is correct
71 Correct 1192 ms 16256 KB Output is correct
72 Correct 1230 ms 16252 KB Output is correct
73 Correct 1201 ms 16248 KB Output is correct
74 Correct 1253 ms 16248 KB Output is correct
75 Correct 1195 ms 16248 KB Output is correct
76 Correct 1212 ms 16252 KB Output is correct
77 Correct 1202 ms 16220 KB Output is correct
78 Correct 1208 ms 16248 KB Output is correct
79 Correct 1201 ms 16344 KB Output is correct
80 Correct 1196 ms 16248 KB Output is correct
81 Correct 1193 ms 16352 KB Output is correct
82 Correct 1218 ms 16248 KB Output is correct
83 Correct 1188 ms 16312 KB Output is correct
84 Correct 1216 ms 16248 KB Output is correct
85 Correct 1200 ms 16348 KB Output is correct
86 Correct 1200 ms 16248 KB Output is correct
87 Correct 1217 ms 16248 KB Output is correct
88 Correct 1280 ms 16244 KB Output is correct
89 Correct 1217 ms 16256 KB Output is correct
90 Correct 1247 ms 16244 KB Output is correct
91 Correct 1186 ms 16248 KB Output is correct
92 Correct 1207 ms 16348 KB Output is correct
93 Correct 1180 ms 16348 KB Output is correct
94 Correct 1206 ms 16348 KB Output is correct
95 Correct 1181 ms 16244 KB Output is correct
96 Correct 1190 ms 16224 KB Output is correct
97 Correct 1220 ms 16248 KB Output is correct
98 Correct 1185 ms 16256 KB Output is correct
99 Correct 1194 ms 16252 KB Output is correct
100 Correct 1142 ms 16248 KB Output is correct
101 Correct 1131 ms 16348 KB Output is correct
102 Correct 1146 ms 16248 KB Output is correct
103 Correct 1163 ms 16252 KB Output is correct
104 Correct 1180 ms 16248 KB Output is correct
105 Correct 1137 ms 16348 KB Output is correct
106 Correct 1143 ms 16248 KB Output is correct
107 Correct 1166 ms 16348 KB Output is correct
108 Correct 1172 ms 16348 KB Output is correct
109 Correct 1136 ms 16344 KB Output is correct
110 Correct 1180 ms 16256 KB Output is correct
111 Correct 1194 ms 16244 KB Output is correct
112 Correct 1187 ms 16248 KB Output is correct
113 Correct 1177 ms 16252 KB Output is correct
114 Correct 1202 ms 16252 KB Output is correct
115 Correct 1198 ms 16248 KB Output is correct
116 Correct 1199 ms 16244 KB Output is correct
117 Correct 1196 ms 16348 KB Output is correct
118 Correct 1193 ms 16348 KB Output is correct
119 Correct 1212 ms 16348 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 1209 ms 16248 KB Output is correct
123 Correct 1193 ms 16276 KB Output is correct
124 Correct 1210 ms 16248 KB Output is correct
125 Correct 1222 ms 16248 KB Output is correct
126 Correct 1216 ms 16248 KB Output is correct
127 Correct 1227 ms 16248 KB Output is correct
128 Correct 1210 ms 16348 KB Output is correct
129 Correct 1214 ms 16348 KB Output is correct
130 Correct 1251 ms 16352 KB Output is correct
131 Correct 1245 ms 16252 KB Output is correct
132 Correct 1177 ms 16244 KB Output is correct
133 Correct 1187 ms 16248 KB Output is correct