답안 #26557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26557 2017-07-03T04:35:52 Z gs14004 Bulldozer (JOI17_bulldozer) C++14
100 / 100
593 ms 33492 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

struct sweep{
	int dx, dy, idx1, idx2;
	int mode(){
		return pi(dx, dy) < pi(0, 0);
	}
	bool operator<(const sweep &s)const{
		lint k = 1ll * dx * s.dy - 1ll * dy * s.dx;
		if(k != 0) return k > 0;
		return pi(idx1, idx2) < pi(s.idx1, s.idx2);
	}
};

lint ccw(sweep a, sweep b){
	return 1ll * a.dx * b.dy - 1ll * b.dx * a.dy;
}

struct point{
	int x, y, c;
	bool operator<(const point &p)const{
		return pi(x, y) < pi(p.x, p.y);
	}
}a[2005];

struct seg{
	struct node{
		lint sum, lsum, rsum, opt;
	}tree[4100];
	int lim;
	node make(int x){
		return (node){x, max(x, 0), max(x, 0), max(x, 0)}; 
	}
	node merge(node a, node b){
		node ans;
		ans.sum = a.sum + b.sum;
		ans.lsum = max(a.lsum, a.sum + b.lsum);
		ans.rsum = max(b.rsum, b.sum + a.rsum);
		ans.opt = max({a.opt, b.opt, a.rsum + b.lsum});
		return ans;
	}
	void init(int n, point *a){
		for(lim = 1; lim <= n; lim <<= 1);
		for(int j=0; j<n; j++){
			tree[j + lim] = make(a[j].c);
		}
		for(int j=lim-1; j>=1; j--){
			tree[j] = merge(tree[2*j], tree[2*j+1]); 
		}
	}
	void update(int x, int v){
		x += lim;
		tree[x] = make(v);
		while(x > 1){
			x >>= 1;
			tree[x] = merge(tree[2*x], tree[2*x+1]);
		}
	}
	lint query(){ return tree[1].opt; }
}seg;

int n, rev[2005];
vector<sweep> v;

int main(){
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i].x >> a[i].y >> a[i].c;
	if(n == 1){
		cout << max(0, a[0].c);
		return 0;
	}
	sort(a, a+n);
	iota(rev, rev + n, 0);
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			v.push_back({a[j].x - a[i].x, a[j].y - a[i].y, i, j});
		}
	}
	sort(v.begin(), v.end());
	seg.init(n, a);
	lint ans = 0;
	for(int i=0; i<v.size(); ){
		int e = i;
		while(e < v.size() && ccw(v[i], v[e]) == 0) e++;
		for(int j=i; j<e; j++){
			int rx = rev[v[j].idx1], ry = rev[v[j].idx2];
			swap(rev[v[j].idx1], rev[v[j].idx2]);
			swap(a[rx], a[ry]);
			seg.update(rx, a[rx].c);
			seg.update(ry, a[ry].c);
		}
		ans = max(ans, seg.query());
		i = e;
	}
	cout << ans;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:85:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); ){
               ~^~~~~~~~~
bulldozer.cpp:87:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(e < v.size() && ccw(v[i], v[e]) == 0) e++;
         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 540 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 412 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 540 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 412 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 540 KB Output is correct
33 Correct 538 ms 33336 KB Output is correct
34 Correct 542 ms 33340 KB Output is correct
35 Correct 553 ms 33340 KB Output is correct
36 Correct 527 ms 33360 KB Output is correct
37 Correct 548 ms 33368 KB Output is correct
38 Correct 562 ms 33344 KB Output is correct
39 Correct 525 ms 33340 KB Output is correct
40 Correct 533 ms 33340 KB Output is correct
41 Correct 529 ms 33340 KB Output is correct
42 Correct 529 ms 33340 KB Output is correct
43 Correct 533 ms 33356 KB Output is correct
44 Correct 539 ms 33340 KB Output is correct
45 Correct 549 ms 33356 KB Output is correct
46 Correct 530 ms 33360 KB Output is correct
47 Correct 547 ms 33356 KB Output is correct
48 Correct 527 ms 33356 KB Output is correct
49 Correct 536 ms 33344 KB Output is correct
50 Correct 524 ms 33356 KB Output is correct
51 Correct 523 ms 33484 KB Output is correct
52 Correct 543 ms 33264 KB Output is correct
53 Correct 542 ms 33340 KB Output is correct
54 Correct 543 ms 33340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 540 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 412 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 540 KB Output is correct
33 Correct 538 ms 33336 KB Output is correct
34 Correct 542 ms 33340 KB Output is correct
35 Correct 553 ms 33340 KB Output is correct
36 Correct 527 ms 33360 KB Output is correct
37 Correct 548 ms 33368 KB Output is correct
38 Correct 562 ms 33344 KB Output is correct
39 Correct 525 ms 33340 KB Output is correct
40 Correct 533 ms 33340 KB Output is correct
41 Correct 529 ms 33340 KB Output is correct
42 Correct 529 ms 33340 KB Output is correct
43 Correct 533 ms 33356 KB Output is correct
44 Correct 539 ms 33340 KB Output is correct
45 Correct 549 ms 33356 KB Output is correct
46 Correct 530 ms 33360 KB Output is correct
47 Correct 547 ms 33356 KB Output is correct
48 Correct 527 ms 33356 KB Output is correct
49 Correct 536 ms 33344 KB Output is correct
50 Correct 524 ms 33356 KB Output is correct
51 Correct 523 ms 33484 KB Output is correct
52 Correct 543 ms 33264 KB Output is correct
53 Correct 542 ms 33340 KB Output is correct
54 Correct 543 ms 33340 KB Output is correct
55 Correct 533 ms 33268 KB Output is correct
56 Correct 521 ms 33356 KB Output is correct
57 Correct 549 ms 33356 KB Output is correct
58 Correct 548 ms 33360 KB Output is correct
59 Correct 556 ms 33468 KB Output is correct
60 Correct 521 ms 33340 KB Output is correct
61 Correct 538 ms 33356 KB Output is correct
62 Correct 534 ms 33356 KB Output is correct
63 Correct 532 ms 33308 KB Output is correct
64 Correct 548 ms 33264 KB Output is correct
65 Correct 528 ms 33340 KB Output is correct
66 Correct 535 ms 33340 KB Output is correct
67 Correct 521 ms 33344 KB Output is correct
68 Correct 528 ms 33340 KB Output is correct
69 Correct 518 ms 33392 KB Output is correct
70 Correct 541 ms 33316 KB Output is correct
71 Correct 563 ms 33348 KB Output is correct
72 Correct 550 ms 33356 KB Output is correct
73 Correct 563 ms 33340 KB Output is correct
74 Correct 543 ms 33356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 3 ms 540 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 412 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 2 ms 304 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 304 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 540 KB Output is correct
48 Correct 538 ms 33336 KB Output is correct
49 Correct 542 ms 33340 KB Output is correct
50 Correct 553 ms 33340 KB Output is correct
51 Correct 527 ms 33360 KB Output is correct
52 Correct 548 ms 33368 KB Output is correct
53 Correct 562 ms 33344 KB Output is correct
54 Correct 525 ms 33340 KB Output is correct
55 Correct 533 ms 33340 KB Output is correct
56 Correct 529 ms 33340 KB Output is correct
57 Correct 529 ms 33340 KB Output is correct
58 Correct 533 ms 33356 KB Output is correct
59 Correct 539 ms 33340 KB Output is correct
60 Correct 549 ms 33356 KB Output is correct
61 Correct 530 ms 33360 KB Output is correct
62 Correct 547 ms 33356 KB Output is correct
63 Correct 527 ms 33356 KB Output is correct
64 Correct 536 ms 33344 KB Output is correct
65 Correct 524 ms 33356 KB Output is correct
66 Correct 523 ms 33484 KB Output is correct
67 Correct 543 ms 33264 KB Output is correct
68 Correct 542 ms 33340 KB Output is correct
69 Correct 543 ms 33340 KB Output is correct
70 Correct 533 ms 33268 KB Output is correct
71 Correct 521 ms 33356 KB Output is correct
72 Correct 549 ms 33356 KB Output is correct
73 Correct 548 ms 33360 KB Output is correct
74 Correct 556 ms 33468 KB Output is correct
75 Correct 521 ms 33340 KB Output is correct
76 Correct 538 ms 33356 KB Output is correct
77 Correct 534 ms 33356 KB Output is correct
78 Correct 532 ms 33308 KB Output is correct
79 Correct 548 ms 33264 KB Output is correct
80 Correct 528 ms 33340 KB Output is correct
81 Correct 535 ms 33340 KB Output is correct
82 Correct 521 ms 33344 KB Output is correct
83 Correct 528 ms 33340 KB Output is correct
84 Correct 518 ms 33392 KB Output is correct
85 Correct 541 ms 33316 KB Output is correct
86 Correct 563 ms 33348 KB Output is correct
87 Correct 550 ms 33356 KB Output is correct
88 Correct 563 ms 33340 KB Output is correct
89 Correct 543 ms 33356 KB Output is correct
90 Correct 541 ms 33328 KB Output is correct
91 Correct 533 ms 33312 KB Output is correct
92 Correct 526 ms 33356 KB Output is correct
93 Correct 529 ms 33492 KB Output is correct
94 Correct 526 ms 33356 KB Output is correct
95 Correct 520 ms 33356 KB Output is correct
96 Correct 534 ms 33328 KB Output is correct
97 Correct 543 ms 33332 KB Output is correct
98 Correct 592 ms 33356 KB Output is correct
99 Correct 554 ms 33340 KB Output is correct
100 Correct 444 ms 33388 KB Output is correct
101 Correct 454 ms 33356 KB Output is correct
102 Correct 454 ms 33340 KB Output is correct
103 Correct 431 ms 33468 KB Output is correct
104 Correct 427 ms 33340 KB Output is correct
105 Correct 480 ms 33340 KB Output is correct
106 Correct 488 ms 33340 KB Output is correct
107 Correct 468 ms 33356 KB Output is correct
108 Correct 463 ms 33276 KB Output is correct
109 Correct 450 ms 33308 KB Output is correct
110 Correct 524 ms 33340 KB Output is correct
111 Correct 564 ms 33288 KB Output is correct
112 Correct 522 ms 33344 KB Output is correct
113 Correct 520 ms 33356 KB Output is correct
114 Correct 515 ms 33356 KB Output is correct
115 Correct 518 ms 33368 KB Output is correct
116 Correct 519 ms 33340 KB Output is correct
117 Correct 532 ms 33312 KB Output is correct
118 Correct 521 ms 33372 KB Output is correct
119 Correct 524 ms 33308 KB Output is correct
120 Correct 2 ms 256 KB Output is correct
121 Correct 2 ms 256 KB Output is correct
122 Correct 554 ms 33356 KB Output is correct
123 Correct 546 ms 33340 KB Output is correct
124 Correct 535 ms 33356 KB Output is correct
125 Correct 540 ms 33356 KB Output is correct
126 Correct 593 ms 33340 KB Output is correct
127 Correct 539 ms 33340 KB Output is correct
128 Correct 529 ms 33340 KB Output is correct
129 Correct 528 ms 33264 KB Output is correct
130 Correct 533 ms 33404 KB Output is correct
131 Correct 539 ms 33368 KB Output is correct
132 Correct 526 ms 33312 KB Output is correct
133 Correct 523 ms 33340 KB Output is correct