답안 #122124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122124 2019-06-27T15:56:03 Z mosesmayer Bulldozer (JOI17_bulldozer) C++17
100 / 100
1333 ms 32452 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define DEBUG
#define fi first
#define se second
#define pb push_back
using namespace std;
//using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
//template<typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//		tree_order_statistics_node_update>; // find_by_order, order_of_key

template<class F, class S>
ostream& operator<< (ostream& os, const pair<F, S> p){
	os << '{' << p.fi << ", " << p.se << '}';
	return os;
}
template<class T>
ostream& operator<< (ostream& os, const vector<T>& v){
	os << '{';
	for (int i = 0, t = v.size(); i < t; i++) os << v[i] << (i+1==t?", " : "}");
	return os;
}
const int INF = 0x3f3f3f3f;
const LL LINF = 1e18;
//////////////////END OF TEMPLATE//////////////////////////////

void read();
struct pt{
	int x, y, v;
	pt(int x = 0, int y = 0, int v = 0): x(x), y(y), v(v) {}
	bool operator== (const pt &rhs) const{ return x == rhs.x && y == rhs.y;}
	bool operator< (const pt &rhs) const{ return x == rhs.x ? y < rhs.y : x < rhs.x; }
	pt operator+ (const pt &rhs){
		return pt(x + rhs.x, y + rhs.y, 0);
	}
	pt operator- (const pt &rhs){
		return pt(x + rhs.x, y + rhs.y, 0);
	}
	LL operator* (const pt &rhs){
		return x * rhs.y - y * rhs.x;
	}
};

struct Node{
	LL a, p, s, b;
	Node(LL v = 0): b(v), a(v), p(v), s(v) {}
};
inline Node merge(Node l, Node r){
	Node x;
	x.a = l.a + r.a;
	x.p = max(l.p, l.a + r.p);
	x.s = max(l.s + r.a, r.s);
	x.b = max(l.b, r.b);
	x.b = max(x.b, l.s + r.p);
	return x;
}


int n;
pt pts[2005];
Node st[2005 << 2];
void build(int p = 1, int l = 1, int r = n){
	if (l ==r){
		st[p] = Node(pts[l].v);
		//cout << l << ' ' << st[p].v << ' ' << st[p].b << '\n';
		return;
	}
	int md = (l + r) >> 1;
	build(p<<1, l, md);
	build(p<<1|1, md+1, r);
	st[p] = merge(st[p<<1], st[p<<1|1]);
}

void upd(int i, int v, int p = 1, int l = 1, int r = n){
	if (l == r) return void(st[p] = Node(v));
	int md = (l + r) >> 1;
	if (i <= md) upd(i, v, p<<1, l, md);
	else upd(i, v, p<<1|1, md+1, r);
	st[p] = merge(st[p<<1], st[p<<1|1]);
}

Node query(int i, int j, int p = 1, int l = 1, int r = n){
	if (j < l || i > r){
		Node ret(-LINF); ret.a = 0;
		return ret;
	}
	if (i <= l && j >= r) return st[p];
	int md = (l + r) >> 1;
	return merge(query(i, j, p<<1, l, md), query(i, j, p<<1|1, md+1, r));
}

void printTree(int p = 1, int l = 1, int r = n){
	cout << "pos " << p << " rng " << make_pair(l, r) << " : " ;
	cout << st[p].a << ' ' << st[p].b << ' ' << st[p].p << ' ' << st[p].s << '\n';
	if (l == r) return;
	int md = (l + r) >> 1;
	printTree(p<<1, l, md);
	printTree(p<<1|1, md+1, r);
}

LL get(){
	return st[1].b;
}
int pos[2005], rpos[2005];
vector<pii> vec;
bool eqv(pii a, pii b){
	LL dxa = pts[a.se].x - pts[a.fi].x;
	LL dya = pts[a.se].y - pts[a.fi].y;
	LL dxb = pts[b.se].x - pts[b.fi].x;
	LL dyb = pts[b.se].y - pts[b.fi].y;
	if (dxa < 0) dxa = -dxa, dya = -dya;
	if (dxb < 0) dxb = -dxb, dyb = -dyb;
	return dya * dxb == dyb * dxa;
}
bool cmp(pii a, pii b){
	if (eqv(a, b)){
		if (pts[a.fi] < pts[a.se]) swap(a.fi, a.se);
		if (pts[b.fi] < pts[b.se]) swap(b.fi, b.se);
		return pts[a.fi] == pts[a.se] ? pts[b.fi] < pts[b.se] : pts[a.fi] < pts[a.se];
	}
	LL dxa = pts[a.se].x - pts[a.fi].x;
	LL dya = pts[a.se].y - pts[a.fi].y;
	LL dxb = pts[b.se].x - pts[b.fi].x;
	LL dyb = pts[b.se].y - pts[b.fi].y;
	if (dxa < 0) dxa = -dxa, dya = -dya;
	if (dxb < 0) dxb = -dxb, dyb = -dyb;
	return dya * dxb < dyb * dxa;
}
bool cmp2(pii a, pii b){
	if (a.fi > a.se) swap(a.fi, a.se);
	if (b.fi > b.se) swap(b.fi, b.se);
	return a < b;
}
vector<pii> curr;
#undef DEBUG
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read();
	build();
	for (int i = 1; i <= n; i++){
		pos[i] = rpos[i] = i;
		for (int j = i+1; j <= n; j++){
			vec.push_back(make_pair(i, j));
		}
	}
	LL mx = 0LL;
	mx = max(mx, get());
	sort(vec.begin(), vec.end(), cmp);
	for (pii v : vec){
		if (curr.empty() || eqv(curr.back(), v)){
			curr.push_back(v);
		} else {
			sort(curr.begin(), curr.end());
			for (pii ii : curr){
				swap(pos[ii.fi], pos[ii.se]);
				upd(pos[ii.fi], pts[ii.fi].v);
				upd(pos[ii.se], pts[ii.se].v);
			}
			mx = max(mx, get());
			curr.clear();
			curr.push_back(v);
		}
	}
	cout << mx << '\n';
	return 0;
}

inline void read(){
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> pts[i].x >> pts[i].y >> pts[i].v;
	sort(pts+1, pts+n+1);
}

Compilation message

bulldozer.cpp: In constructor 'Node::Node(LL)':
bulldozer.cpp:50:14: warning: 'Node::b' will be initialized after [-Wreorder]
  LL a, p, s, b;
              ^
bulldozer.cpp:50:5: warning:   'LL Node::a' [-Wreorder]
  LL a, p, s, b;
     ^
bulldozer.cpp:51:2: warning:   when initialized here [-Wreorder]
  Node(LL v = 0): b(v), a(v), p(v), s(v) {}
  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 3 ms 788 KB Output is correct
9 Correct 3 ms 768 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
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 5 ms 704 KB Output is correct
10 Correct 4 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 2 ms 640 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 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 5 ms 704 KB Output is correct
10 Correct 4 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 2 ms 640 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 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 1303 ms 17260 KB Output is correct
34 Correct 1240 ms 17260 KB Output is correct
35 Correct 1231 ms 17256 KB Output is correct
36 Correct 1212 ms 17260 KB Output is correct
37 Correct 1267 ms 17252 KB Output is correct
38 Correct 1206 ms 17252 KB Output is correct
39 Correct 1232 ms 17260 KB Output is correct
40 Correct 1296 ms 17372 KB Output is correct
41 Correct 1285 ms 17252 KB Output is correct
42 Correct 1252 ms 17368 KB Output is correct
43 Correct 1275 ms 17260 KB Output is correct
44 Correct 1210 ms 17252 KB Output is correct
45 Correct 1190 ms 17216 KB Output is correct
46 Correct 1200 ms 17252 KB Output is correct
47 Correct 1189 ms 17260 KB Output is correct
48 Correct 1226 ms 17252 KB Output is correct
49 Correct 1222 ms 17256 KB Output is correct
50 Correct 1210 ms 17312 KB Output is correct
51 Correct 1222 ms 17252 KB Output is correct
52 Correct 1223 ms 17248 KB Output is correct
53 Correct 1206 ms 17248 KB Output is correct
54 Correct 1330 ms 17256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 5 ms 704 KB Output is correct
10 Correct 4 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 2 ms 640 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 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 1303 ms 17260 KB Output is correct
34 Correct 1240 ms 17260 KB Output is correct
35 Correct 1231 ms 17256 KB Output is correct
36 Correct 1212 ms 17260 KB Output is correct
37 Correct 1267 ms 17252 KB Output is correct
38 Correct 1206 ms 17252 KB Output is correct
39 Correct 1232 ms 17260 KB Output is correct
40 Correct 1296 ms 17372 KB Output is correct
41 Correct 1285 ms 17252 KB Output is correct
42 Correct 1252 ms 17368 KB Output is correct
43 Correct 1275 ms 17260 KB Output is correct
44 Correct 1210 ms 17252 KB Output is correct
45 Correct 1190 ms 17216 KB Output is correct
46 Correct 1200 ms 17252 KB Output is correct
47 Correct 1189 ms 17260 KB Output is correct
48 Correct 1226 ms 17252 KB Output is correct
49 Correct 1222 ms 17256 KB Output is correct
50 Correct 1210 ms 17312 KB Output is correct
51 Correct 1222 ms 17252 KB Output is correct
52 Correct 1223 ms 17248 KB Output is correct
53 Correct 1206 ms 17248 KB Output is correct
54 Correct 1330 ms 17256 KB Output is correct
55 Correct 1208 ms 17248 KB Output is correct
56 Correct 1208 ms 17252 KB Output is correct
57 Correct 1251 ms 17260 KB Output is correct
58 Correct 1213 ms 17252 KB Output is correct
59 Correct 1207 ms 17260 KB Output is correct
60 Correct 1216 ms 17308 KB Output is correct
61 Correct 1221 ms 17260 KB Output is correct
62 Correct 1230 ms 17260 KB Output is correct
63 Correct 1227 ms 17260 KB Output is correct
64 Correct 1210 ms 17260 KB Output is correct
65 Correct 1204 ms 17260 KB Output is correct
66 Correct 1234 ms 17260 KB Output is correct
67 Correct 1197 ms 17336 KB Output is correct
68 Correct 1212 ms 17260 KB Output is correct
69 Correct 1193 ms 17260 KB Output is correct
70 Correct 1266 ms 17252 KB Output is correct
71 Correct 1202 ms 17260 KB Output is correct
72 Correct 1247 ms 17260 KB Output is correct
73 Correct 1237 ms 17244 KB Output is correct
74 Correct 1220 ms 17252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 3 ms 788 KB Output is correct
9 Correct 3 ms 768 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 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 5 ms 704 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 2 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 2 ms 640 KB Output is correct
30 Correct 2 ms 640 KB Output is correct
31 Correct 2 ms 640 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 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 4 ms 768 KB Output is correct
37 Correct 5 ms 768 KB Output is correct
38 Correct 4 ms 768 KB Output is correct
39 Correct 4 ms 768 KB Output is correct
40 Correct 4 ms 768 KB Output is correct
41 Correct 4 ms 768 KB Output is correct
42 Correct 4 ms 768 KB Output is correct
43 Correct 4 ms 768 KB Output is correct
44 Correct 4 ms 768 KB Output is correct
45 Correct 4 ms 768 KB Output is correct
46 Correct 4 ms 768 KB Output is correct
47 Correct 4 ms 768 KB Output is correct
48 Correct 1303 ms 17260 KB Output is correct
49 Correct 1240 ms 17260 KB Output is correct
50 Correct 1231 ms 17256 KB Output is correct
51 Correct 1212 ms 17260 KB Output is correct
52 Correct 1267 ms 17252 KB Output is correct
53 Correct 1206 ms 17252 KB Output is correct
54 Correct 1232 ms 17260 KB Output is correct
55 Correct 1296 ms 17372 KB Output is correct
56 Correct 1285 ms 17252 KB Output is correct
57 Correct 1252 ms 17368 KB Output is correct
58 Correct 1275 ms 17260 KB Output is correct
59 Correct 1210 ms 17252 KB Output is correct
60 Correct 1190 ms 17216 KB Output is correct
61 Correct 1200 ms 17252 KB Output is correct
62 Correct 1189 ms 17260 KB Output is correct
63 Correct 1226 ms 17252 KB Output is correct
64 Correct 1222 ms 17256 KB Output is correct
65 Correct 1210 ms 17312 KB Output is correct
66 Correct 1222 ms 17252 KB Output is correct
67 Correct 1223 ms 17248 KB Output is correct
68 Correct 1206 ms 17248 KB Output is correct
69 Correct 1330 ms 17256 KB Output is correct
70 Correct 1208 ms 17248 KB Output is correct
71 Correct 1208 ms 17252 KB Output is correct
72 Correct 1251 ms 17260 KB Output is correct
73 Correct 1213 ms 17252 KB Output is correct
74 Correct 1207 ms 17260 KB Output is correct
75 Correct 1216 ms 17308 KB Output is correct
76 Correct 1221 ms 17260 KB Output is correct
77 Correct 1230 ms 17260 KB Output is correct
78 Correct 1227 ms 17260 KB Output is correct
79 Correct 1210 ms 17260 KB Output is correct
80 Correct 1204 ms 17260 KB Output is correct
81 Correct 1234 ms 17260 KB Output is correct
82 Correct 1197 ms 17336 KB Output is correct
83 Correct 1212 ms 17260 KB Output is correct
84 Correct 1193 ms 17260 KB Output is correct
85 Correct 1266 ms 17252 KB Output is correct
86 Correct 1202 ms 17260 KB Output is correct
87 Correct 1247 ms 17260 KB Output is correct
88 Correct 1237 ms 17244 KB Output is correct
89 Correct 1220 ms 17252 KB Output is correct
90 Correct 1264 ms 17252 KB Output is correct
91 Correct 1231 ms 17280 KB Output is correct
92 Correct 1253 ms 17260 KB Output is correct
93 Correct 1275 ms 17260 KB Output is correct
94 Correct 1196 ms 17252 KB Output is correct
95 Correct 1238 ms 17324 KB Output is correct
96 Correct 1255 ms 17252 KB Output is correct
97 Correct 1310 ms 17260 KB Output is correct
98 Correct 1273 ms 17388 KB Output is correct
99 Correct 1290 ms 17404 KB Output is correct
100 Correct 886 ms 32380 KB Output is correct
101 Correct 855 ms 32452 KB Output is correct
102 Correct 866 ms 32448 KB Output is correct
103 Correct 883 ms 32388 KB Output is correct
104 Correct 906 ms 32324 KB Output is correct
105 Correct 986 ms 29760 KB Output is correct
106 Correct 984 ms 29816 KB Output is correct
107 Correct 975 ms 29728 KB Output is correct
108 Correct 975 ms 29728 KB Output is correct
109 Correct 980 ms 29692 KB Output is correct
110 Correct 1135 ms 17260 KB Output is correct
111 Correct 1106 ms 17260 KB Output is correct
112 Correct 1140 ms 17252 KB Output is correct
113 Correct 1149 ms 17236 KB Output is correct
114 Correct 1140 ms 17244 KB Output is correct
115 Correct 1107 ms 17260 KB Output is correct
116 Correct 1104 ms 17388 KB Output is correct
117 Correct 1121 ms 17252 KB Output is correct
118 Correct 1106 ms 17248 KB Output is correct
119 Correct 1079 ms 17260 KB Output is correct
120 Correct 2 ms 640 KB Output is correct
121 Correct 2 ms 640 KB Output is correct
122 Correct 1213 ms 17260 KB Output is correct
123 Correct 1218 ms 17260 KB Output is correct
124 Correct 1241 ms 17252 KB Output is correct
125 Correct 1223 ms 17252 KB Output is correct
126 Correct 1197 ms 17252 KB Output is correct
127 Correct 1228 ms 17260 KB Output is correct
128 Correct 1201 ms 17252 KB Output is correct
129 Correct 1333 ms 17236 KB Output is correct
130 Correct 1213 ms 17248 KB Output is correct
131 Correct 1237 ms 17252 KB Output is correct
132 Correct 1291 ms 17252 KB Output is correct
133 Correct 1257 ms 17252 KB Output is correct