답안 #102723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102723 2019-03-27T08:39:14 Z Minnakhmetov Bulldozer (JOI17_bulldozer) C++14
100 / 100
1182 ms 16476 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);
	}
}

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 };
			if (a[j].x > a[i].x || a[j].x == a[i].x && a[j].y < a[i].y) {
				swap(z[ct].first, z[ct].second);
			}
			ct++;
		}
	}

	build();

	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];
		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 function 'int main()':
bulldozer.cpp:142:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if (a[j].x > a[i].x || a[j].x == a[i].x && a[j].y < a[i].y) {
                           ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 384 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 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 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 476 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 3 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 3 ms 384 KB Output is correct
9 Correct 4 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 384 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 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 4 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 476 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 3 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 3 ms 384 KB Output is correct
9 Correct 4 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 384 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 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 4 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 1079 ms 16256 KB Output is correct
34 Correct 1084 ms 16252 KB Output is correct
35 Correct 1085 ms 16260 KB Output is correct
36 Correct 1071 ms 16248 KB Output is correct
37 Correct 1071 ms 16244 KB Output is correct
38 Correct 1080 ms 16356 KB Output is correct
39 Correct 1087 ms 16344 KB Output is correct
40 Correct 1085 ms 16352 KB Output is correct
41 Correct 1086 ms 16248 KB Output is correct
42 Correct 1064 ms 16344 KB Output is correct
43 Correct 1067 ms 16220 KB Output is correct
44 Correct 1067 ms 16348 KB Output is correct
45 Correct 1075 ms 16248 KB Output is correct
46 Correct 1075 ms 16248 KB Output is correct
47 Correct 1085 ms 16248 KB Output is correct
48 Correct 1062 ms 16348 KB Output is correct
49 Correct 1073 ms 16248 KB Output is correct
50 Correct 1097 ms 16248 KB Output is correct
51 Correct 1101 ms 16248 KB Output is correct
52 Correct 1067 ms 16356 KB Output is correct
53 Correct 1065 ms 16252 KB Output is correct
54 Correct 1070 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 476 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 3 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 3 ms 384 KB Output is correct
9 Correct 4 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 384 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 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 4 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 1079 ms 16256 KB Output is correct
34 Correct 1084 ms 16252 KB Output is correct
35 Correct 1085 ms 16260 KB Output is correct
36 Correct 1071 ms 16248 KB Output is correct
37 Correct 1071 ms 16244 KB Output is correct
38 Correct 1080 ms 16356 KB Output is correct
39 Correct 1087 ms 16344 KB Output is correct
40 Correct 1085 ms 16352 KB Output is correct
41 Correct 1086 ms 16248 KB Output is correct
42 Correct 1064 ms 16344 KB Output is correct
43 Correct 1067 ms 16220 KB Output is correct
44 Correct 1067 ms 16348 KB Output is correct
45 Correct 1075 ms 16248 KB Output is correct
46 Correct 1075 ms 16248 KB Output is correct
47 Correct 1085 ms 16248 KB Output is correct
48 Correct 1062 ms 16348 KB Output is correct
49 Correct 1073 ms 16248 KB Output is correct
50 Correct 1097 ms 16248 KB Output is correct
51 Correct 1101 ms 16248 KB Output is correct
52 Correct 1067 ms 16356 KB Output is correct
53 Correct 1065 ms 16252 KB Output is correct
54 Correct 1070 ms 16220 KB Output is correct
55 Correct 1067 ms 16252 KB Output is correct
56 Correct 1079 ms 16224 KB Output is correct
57 Correct 1074 ms 16256 KB Output is correct
58 Correct 1095 ms 16252 KB Output is correct
59 Correct 1076 ms 16248 KB Output is correct
60 Correct 1084 ms 16248 KB Output is correct
61 Correct 1077 ms 16244 KB Output is correct
62 Correct 1099 ms 16252 KB Output is correct
63 Correct 1102 ms 16244 KB Output is correct
64 Correct 1109 ms 16360 KB Output is correct
65 Correct 1088 ms 16244 KB Output is correct
66 Correct 1073 ms 16248 KB Output is correct
67 Correct 1084 ms 16248 KB Output is correct
68 Correct 1129 ms 16252 KB Output is correct
69 Correct 1102 ms 16256 KB Output is correct
70 Correct 1157 ms 16252 KB Output is correct
71 Correct 1072 ms 16244 KB Output is correct
72 Correct 1129 ms 16248 KB Output is correct
73 Correct 1122 ms 16276 KB Output is correct
74 Correct 1086 ms 16476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 384 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 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 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 476 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 3 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 4 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 384 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 3 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 4 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 1079 ms 16256 KB Output is correct
49 Correct 1084 ms 16252 KB Output is correct
50 Correct 1085 ms 16260 KB Output is correct
51 Correct 1071 ms 16248 KB Output is correct
52 Correct 1071 ms 16244 KB Output is correct
53 Correct 1080 ms 16356 KB Output is correct
54 Correct 1087 ms 16344 KB Output is correct
55 Correct 1085 ms 16352 KB Output is correct
56 Correct 1086 ms 16248 KB Output is correct
57 Correct 1064 ms 16344 KB Output is correct
58 Correct 1067 ms 16220 KB Output is correct
59 Correct 1067 ms 16348 KB Output is correct
60 Correct 1075 ms 16248 KB Output is correct
61 Correct 1075 ms 16248 KB Output is correct
62 Correct 1085 ms 16248 KB Output is correct
63 Correct 1062 ms 16348 KB Output is correct
64 Correct 1073 ms 16248 KB Output is correct
65 Correct 1097 ms 16248 KB Output is correct
66 Correct 1101 ms 16248 KB Output is correct
67 Correct 1067 ms 16356 KB Output is correct
68 Correct 1065 ms 16252 KB Output is correct
69 Correct 1070 ms 16220 KB Output is correct
70 Correct 1067 ms 16252 KB Output is correct
71 Correct 1079 ms 16224 KB Output is correct
72 Correct 1074 ms 16256 KB Output is correct
73 Correct 1095 ms 16252 KB Output is correct
74 Correct 1076 ms 16248 KB Output is correct
75 Correct 1084 ms 16248 KB Output is correct
76 Correct 1077 ms 16244 KB Output is correct
77 Correct 1099 ms 16252 KB Output is correct
78 Correct 1102 ms 16244 KB Output is correct
79 Correct 1109 ms 16360 KB Output is correct
80 Correct 1088 ms 16244 KB Output is correct
81 Correct 1073 ms 16248 KB Output is correct
82 Correct 1084 ms 16248 KB Output is correct
83 Correct 1129 ms 16252 KB Output is correct
84 Correct 1102 ms 16256 KB Output is correct
85 Correct 1157 ms 16252 KB Output is correct
86 Correct 1072 ms 16244 KB Output is correct
87 Correct 1129 ms 16248 KB Output is correct
88 Correct 1122 ms 16276 KB Output is correct
89 Correct 1086 ms 16476 KB Output is correct
90 Correct 1090 ms 16256 KB Output is correct
91 Correct 1073 ms 16348 KB Output is correct
92 Correct 1098 ms 16252 KB Output is correct
93 Correct 1100 ms 16248 KB Output is correct
94 Correct 1079 ms 16252 KB Output is correct
95 Correct 1095 ms 16244 KB Output is correct
96 Correct 1082 ms 16248 KB Output is correct
97 Correct 1107 ms 16252 KB Output is correct
98 Correct 1097 ms 16248 KB Output is correct
99 Correct 1131 ms 16256 KB Output is correct
100 Correct 1008 ms 16252 KB Output is correct
101 Correct 1006 ms 16248 KB Output is correct
102 Correct 1022 ms 16252 KB Output is correct
103 Correct 1002 ms 16248 KB Output is correct
104 Correct 1004 ms 16376 KB Output is correct
105 Correct 1020 ms 16248 KB Output is correct
106 Correct 1030 ms 16248 KB Output is correct
107 Correct 1012 ms 16248 KB Output is correct
108 Correct 1010 ms 16256 KB Output is correct
109 Correct 1053 ms 16244 KB Output is correct
110 Correct 1052 ms 16128 KB Output is correct
111 Correct 1069 ms 16248 KB Output is correct
112 Correct 1057 ms 16248 KB Output is correct
113 Correct 1047 ms 16248 KB Output is correct
114 Correct 1087 ms 16244 KB Output is correct
115 Correct 1052 ms 16252 KB Output is correct
116 Correct 1050 ms 16244 KB Output is correct
117 Correct 1083 ms 16244 KB Output is correct
118 Correct 1078 ms 16248 KB Output is correct
119 Correct 1182 ms 16248 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 1081 ms 16248 KB Output is correct
123 Correct 1084 ms 16244 KB Output is correct
124 Correct 1123 ms 16252 KB Output is correct
125 Correct 1117 ms 16292 KB Output is correct
126 Correct 1163 ms 16248 KB Output is correct
127 Correct 1103 ms 16252 KB Output is correct
128 Correct 1088 ms 16348 KB Output is correct
129 Correct 1114 ms 16348 KB Output is correct
130 Correct 1099 ms 16348 KB Output is correct
131 Correct 1070 ms 16348 KB Output is correct
132 Correct 1081 ms 16248 KB Output is correct
133 Correct 1072 ms 16248 KB Output is correct