답안 #26604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26604 2017-07-03T12:43:14 Z kriii Bulldozer (JOI17_bulldozer) C++14
100 / 100
1477 ms 188492 KB
#include <stdio.h>
#include <algorithm>
using namespace std;

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

int N; long long A, B;

struct point{
	int x, y, c, i;
	bool operator <(const point &t) const{
		if (y != t.y) return y < t.y;
		return x < t.x;
	}
}P[2000];
int R[2000];

struct turn{
	turn(){
		dx = dy = 0;
	}
	turn(point a, point b){
		dx = b.x - a.x;
		dy = b.y - a.y;
		long long g = gcd(abs(dx), abs(dy));
		dx /= g;
		dy /= g;
		s = dx * a.x + dy * a.y;
		e = dx * b.x + dy * b.y;
		i = a.i;
		j = b.i;
		tp = type();
	}
	long long dx, dy, s, e;
	int i, j, tp;

	int type() const{
		if (dy > 0 || (dx > 0 && dy == 0)) return 0;
		return 1;
	}
	bool operator <(const turn &t) const{
		if (tp != t.tp) return tp < t.tp;
		if (dy * t.dx != t.dy * dx) return dy * t.dx < t.dy * dx;
		if (e != t.e) return e > t.e;
		return s > t.s;
	};
}T[4000000];

const int Z = 1<<11;

struct node{
	node()
	{
		l = r = s = m = 0;
	}
	node(long long x)
	{
		if (x > 0) l = r = s = m = x;
		else{
			l = r = m = 0;
			s = x;
		}
	}

	long long l,r,s,m;
	
	node operator + (const node &t) const{
		node res;
		res.l = max(l,s+t.l);
		res.r = max(r+t.s,t.r);
		res.s = s + t.s;
		res.m = max({m,t.m,r+t.l});
		return res;
	}
}IT[Z*2];

void up(int x, long long v)
{
	x += Z; IT[x] = node(v); x /= 2;
	while (x){
		IT[x] = IT[x*2] + IT[x*2+1];
		x /= 2;
	}
}

int main()
{
	scanf("%d", &N);

	for (int i=0;i<N;i++){
		scanf("%d %d %d", &P[i].x, &P[i].y, &P[i].c);
		P[i].i = i;
	}
	sort(P, P+N);
	for (int i=0;i<N;i++){
		R[P[i].i] = i;
		IT[i+Z] = node(P[i].c);
	}
	for (int i=Z-1;i>=1;i--) IT[i] = IT[i*2] + IT[i*2+1];

	int c = 0;
	for (int i=0;i<N;i++) for (int j=0;j<N;j++) if (i < j){
		T[c++] = turn(P[i], P[j]);
	}
	sort(T, T+c);

	long long ans = max(0ll,IT[1].m);
	for (int i=0, j=0; i < c; i = j){
		while (j < c && T[i].dx == T[j].dx && T[i].dy == T[j].dy){
			int &x = R[T[j].i];
			int &y = R[T[j].j];
			swap(P[x], P[y]);
			swap(x, y);
			up(x,P[x].c);
			up(y,P[y].c);
			j++;
		}
		ans = max(ans,IT[1].m);
	}
	printf("%lld\n", ans);

	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
bulldozer.cpp:94:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &P[i].x, &P[i].y, &P[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 188336 KB Output is correct
2 Correct 133 ms 188244 KB Output is correct
3 Correct 142 ms 188256 KB Output is correct
4 Correct 132 ms 188340 KB Output is correct
5 Correct 136 ms 188292 KB Output is correct
6 Correct 132 ms 188232 KB Output is correct
7 Correct 129 ms 188236 KB Output is correct
8 Correct 127 ms 188344 KB Output is correct
9 Correct 141 ms 188256 KB Output is correct
10 Correct 130 ms 188400 KB Output is correct
11 Correct 128 ms 188280 KB Output is correct
12 Correct 130 ms 188328 KB Output is correct
13 Correct 130 ms 188356 KB Output is correct
14 Correct 128 ms 188232 KB Output is correct
15 Correct 128 ms 188280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 188244 KB Output is correct
2 Correct 131 ms 188252 KB Output is correct
3 Correct 127 ms 188304 KB Output is correct
4 Correct 126 ms 188280 KB Output is correct
5 Correct 130 ms 188280 KB Output is correct
6 Correct 126 ms 188280 KB Output is correct
7 Correct 126 ms 188280 KB Output is correct
8 Correct 131 ms 188328 KB Output is correct
9 Correct 129 ms 188256 KB Output is correct
10 Correct 129 ms 188372 KB Output is correct
11 Correct 141 ms 188280 KB Output is correct
12 Correct 133 ms 188280 KB Output is correct
13 Correct 127 ms 188272 KB Output is correct
14 Correct 127 ms 188280 KB Output is correct
15 Correct 131 ms 188280 KB Output is correct
16 Correct 125 ms 188412 KB Output is correct
17 Correct 125 ms 188252 KB Output is correct
18 Correct 124 ms 188280 KB Output is correct
19 Correct 129 ms 188352 KB Output is correct
20 Correct 127 ms 188280 KB Output is correct
21 Correct 128 ms 188308 KB Output is correct
22 Correct 136 ms 188280 KB Output is correct
23 Correct 128 ms 188408 KB Output is correct
24 Correct 130 ms 188220 KB Output is correct
25 Correct 125 ms 188280 KB Output is correct
26 Correct 125 ms 188248 KB Output is correct
27 Correct 128 ms 188280 KB Output is correct
28 Correct 126 ms 188280 KB Output is correct
29 Correct 126 ms 188280 KB Output is correct
30 Correct 138 ms 188344 KB Output is correct
31 Correct 133 ms 188280 KB Output is correct
32 Correct 134 ms 188300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 188244 KB Output is correct
2 Correct 131 ms 188252 KB Output is correct
3 Correct 127 ms 188304 KB Output is correct
4 Correct 126 ms 188280 KB Output is correct
5 Correct 130 ms 188280 KB Output is correct
6 Correct 126 ms 188280 KB Output is correct
7 Correct 126 ms 188280 KB Output is correct
8 Correct 131 ms 188328 KB Output is correct
9 Correct 129 ms 188256 KB Output is correct
10 Correct 129 ms 188372 KB Output is correct
11 Correct 141 ms 188280 KB Output is correct
12 Correct 133 ms 188280 KB Output is correct
13 Correct 127 ms 188272 KB Output is correct
14 Correct 127 ms 188280 KB Output is correct
15 Correct 131 ms 188280 KB Output is correct
16 Correct 125 ms 188412 KB Output is correct
17 Correct 125 ms 188252 KB Output is correct
18 Correct 124 ms 188280 KB Output is correct
19 Correct 129 ms 188352 KB Output is correct
20 Correct 127 ms 188280 KB Output is correct
21 Correct 128 ms 188308 KB Output is correct
22 Correct 136 ms 188280 KB Output is correct
23 Correct 128 ms 188408 KB Output is correct
24 Correct 130 ms 188220 KB Output is correct
25 Correct 125 ms 188280 KB Output is correct
26 Correct 125 ms 188248 KB Output is correct
27 Correct 128 ms 188280 KB Output is correct
28 Correct 126 ms 188280 KB Output is correct
29 Correct 126 ms 188280 KB Output is correct
30 Correct 138 ms 188344 KB Output is correct
31 Correct 133 ms 188280 KB Output is correct
32 Correct 134 ms 188300 KB Output is correct
33 Correct 1370 ms 188376 KB Output is correct
34 Correct 1368 ms 188376 KB Output is correct
35 Correct 1385 ms 188372 KB Output is correct
36 Correct 1407 ms 188368 KB Output is correct
37 Correct 1383 ms 188376 KB Output is correct
38 Correct 1333 ms 188372 KB Output is correct
39 Correct 1372 ms 188372 KB Output is correct
40 Correct 1352 ms 188364 KB Output is correct
41 Correct 1369 ms 188368 KB Output is correct
42 Correct 1361 ms 188368 KB Output is correct
43 Correct 1264 ms 188372 KB Output is correct
44 Correct 1246 ms 188372 KB Output is correct
45 Correct 1237 ms 188372 KB Output is correct
46 Correct 1272 ms 188380 KB Output is correct
47 Correct 1290 ms 188416 KB Output is correct
48 Correct 1282 ms 188372 KB Output is correct
49 Correct 1291 ms 188376 KB Output is correct
50 Correct 1318 ms 188372 KB Output is correct
51 Correct 1278 ms 188372 KB Output is correct
52 Correct 1249 ms 188392 KB Output is correct
53 Correct 1256 ms 188376 KB Output is correct
54 Correct 1259 ms 188376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 188244 KB Output is correct
2 Correct 131 ms 188252 KB Output is correct
3 Correct 127 ms 188304 KB Output is correct
4 Correct 126 ms 188280 KB Output is correct
5 Correct 130 ms 188280 KB Output is correct
6 Correct 126 ms 188280 KB Output is correct
7 Correct 126 ms 188280 KB Output is correct
8 Correct 131 ms 188328 KB Output is correct
9 Correct 129 ms 188256 KB Output is correct
10 Correct 129 ms 188372 KB Output is correct
11 Correct 141 ms 188280 KB Output is correct
12 Correct 133 ms 188280 KB Output is correct
13 Correct 127 ms 188272 KB Output is correct
14 Correct 127 ms 188280 KB Output is correct
15 Correct 131 ms 188280 KB Output is correct
16 Correct 125 ms 188412 KB Output is correct
17 Correct 125 ms 188252 KB Output is correct
18 Correct 124 ms 188280 KB Output is correct
19 Correct 129 ms 188352 KB Output is correct
20 Correct 127 ms 188280 KB Output is correct
21 Correct 128 ms 188308 KB Output is correct
22 Correct 136 ms 188280 KB Output is correct
23 Correct 128 ms 188408 KB Output is correct
24 Correct 130 ms 188220 KB Output is correct
25 Correct 125 ms 188280 KB Output is correct
26 Correct 125 ms 188248 KB Output is correct
27 Correct 128 ms 188280 KB Output is correct
28 Correct 126 ms 188280 KB Output is correct
29 Correct 126 ms 188280 KB Output is correct
30 Correct 138 ms 188344 KB Output is correct
31 Correct 133 ms 188280 KB Output is correct
32 Correct 134 ms 188300 KB Output is correct
33 Correct 1370 ms 188376 KB Output is correct
34 Correct 1368 ms 188376 KB Output is correct
35 Correct 1385 ms 188372 KB Output is correct
36 Correct 1407 ms 188368 KB Output is correct
37 Correct 1383 ms 188376 KB Output is correct
38 Correct 1333 ms 188372 KB Output is correct
39 Correct 1372 ms 188372 KB Output is correct
40 Correct 1352 ms 188364 KB Output is correct
41 Correct 1369 ms 188368 KB Output is correct
42 Correct 1361 ms 188368 KB Output is correct
43 Correct 1264 ms 188372 KB Output is correct
44 Correct 1246 ms 188372 KB Output is correct
45 Correct 1237 ms 188372 KB Output is correct
46 Correct 1272 ms 188380 KB Output is correct
47 Correct 1290 ms 188416 KB Output is correct
48 Correct 1282 ms 188372 KB Output is correct
49 Correct 1291 ms 188376 KB Output is correct
50 Correct 1318 ms 188372 KB Output is correct
51 Correct 1278 ms 188372 KB Output is correct
52 Correct 1249 ms 188392 KB Output is correct
53 Correct 1256 ms 188376 KB Output is correct
54 Correct 1259 ms 188376 KB Output is correct
55 Correct 1437 ms 188376 KB Output is correct
56 Correct 1336 ms 188376 KB Output is correct
57 Correct 1358 ms 188376 KB Output is correct
58 Correct 1409 ms 188368 KB Output is correct
59 Correct 1441 ms 188368 KB Output is correct
60 Correct 1419 ms 188368 KB Output is correct
61 Correct 1445 ms 188372 KB Output is correct
62 Correct 1375 ms 188372 KB Output is correct
63 Correct 1354 ms 188368 KB Output is correct
64 Correct 1358 ms 188372 KB Output is correct
65 Correct 1338 ms 188372 KB Output is correct
66 Correct 1342 ms 188372 KB Output is correct
67 Correct 1350 ms 188368 KB Output is correct
68 Correct 1368 ms 188376 KB Output is correct
69 Correct 1358 ms 188380 KB Output is correct
70 Correct 1361 ms 188368 KB Output is correct
71 Correct 1395 ms 188480 KB Output is correct
72 Correct 1373 ms 188368 KB Output is correct
73 Correct 1363 ms 188372 KB Output is correct
74 Correct 1361 ms 188368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 188336 KB Output is correct
2 Correct 133 ms 188244 KB Output is correct
3 Correct 142 ms 188256 KB Output is correct
4 Correct 132 ms 188340 KB Output is correct
5 Correct 136 ms 188292 KB Output is correct
6 Correct 132 ms 188232 KB Output is correct
7 Correct 129 ms 188236 KB Output is correct
8 Correct 127 ms 188344 KB Output is correct
9 Correct 141 ms 188256 KB Output is correct
10 Correct 130 ms 188400 KB Output is correct
11 Correct 128 ms 188280 KB Output is correct
12 Correct 130 ms 188328 KB Output is correct
13 Correct 130 ms 188356 KB Output is correct
14 Correct 128 ms 188232 KB Output is correct
15 Correct 128 ms 188280 KB Output is correct
16 Correct 133 ms 188244 KB Output is correct
17 Correct 131 ms 188252 KB Output is correct
18 Correct 127 ms 188304 KB Output is correct
19 Correct 126 ms 188280 KB Output is correct
20 Correct 130 ms 188280 KB Output is correct
21 Correct 126 ms 188280 KB Output is correct
22 Correct 126 ms 188280 KB Output is correct
23 Correct 131 ms 188328 KB Output is correct
24 Correct 129 ms 188256 KB Output is correct
25 Correct 129 ms 188372 KB Output is correct
26 Correct 141 ms 188280 KB Output is correct
27 Correct 133 ms 188280 KB Output is correct
28 Correct 127 ms 188272 KB Output is correct
29 Correct 127 ms 188280 KB Output is correct
30 Correct 131 ms 188280 KB Output is correct
31 Correct 125 ms 188412 KB Output is correct
32 Correct 125 ms 188252 KB Output is correct
33 Correct 124 ms 188280 KB Output is correct
34 Correct 129 ms 188352 KB Output is correct
35 Correct 127 ms 188280 KB Output is correct
36 Correct 128 ms 188308 KB Output is correct
37 Correct 136 ms 188280 KB Output is correct
38 Correct 128 ms 188408 KB Output is correct
39 Correct 130 ms 188220 KB Output is correct
40 Correct 125 ms 188280 KB Output is correct
41 Correct 125 ms 188248 KB Output is correct
42 Correct 128 ms 188280 KB Output is correct
43 Correct 126 ms 188280 KB Output is correct
44 Correct 126 ms 188280 KB Output is correct
45 Correct 138 ms 188344 KB Output is correct
46 Correct 133 ms 188280 KB Output is correct
47 Correct 134 ms 188300 KB Output is correct
48 Correct 1370 ms 188376 KB Output is correct
49 Correct 1368 ms 188376 KB Output is correct
50 Correct 1385 ms 188372 KB Output is correct
51 Correct 1407 ms 188368 KB Output is correct
52 Correct 1383 ms 188376 KB Output is correct
53 Correct 1333 ms 188372 KB Output is correct
54 Correct 1372 ms 188372 KB Output is correct
55 Correct 1352 ms 188364 KB Output is correct
56 Correct 1369 ms 188368 KB Output is correct
57 Correct 1361 ms 188368 KB Output is correct
58 Correct 1264 ms 188372 KB Output is correct
59 Correct 1246 ms 188372 KB Output is correct
60 Correct 1237 ms 188372 KB Output is correct
61 Correct 1272 ms 188380 KB Output is correct
62 Correct 1290 ms 188416 KB Output is correct
63 Correct 1282 ms 188372 KB Output is correct
64 Correct 1291 ms 188376 KB Output is correct
65 Correct 1318 ms 188372 KB Output is correct
66 Correct 1278 ms 188372 KB Output is correct
67 Correct 1249 ms 188392 KB Output is correct
68 Correct 1256 ms 188376 KB Output is correct
69 Correct 1259 ms 188376 KB Output is correct
70 Correct 1437 ms 188376 KB Output is correct
71 Correct 1336 ms 188376 KB Output is correct
72 Correct 1358 ms 188376 KB Output is correct
73 Correct 1409 ms 188368 KB Output is correct
74 Correct 1441 ms 188368 KB Output is correct
75 Correct 1419 ms 188368 KB Output is correct
76 Correct 1445 ms 188372 KB Output is correct
77 Correct 1375 ms 188372 KB Output is correct
78 Correct 1354 ms 188368 KB Output is correct
79 Correct 1358 ms 188372 KB Output is correct
80 Correct 1338 ms 188372 KB Output is correct
81 Correct 1342 ms 188372 KB Output is correct
82 Correct 1350 ms 188368 KB Output is correct
83 Correct 1368 ms 188376 KB Output is correct
84 Correct 1358 ms 188380 KB Output is correct
85 Correct 1361 ms 188368 KB Output is correct
86 Correct 1395 ms 188480 KB Output is correct
87 Correct 1373 ms 188368 KB Output is correct
88 Correct 1363 ms 188372 KB Output is correct
89 Correct 1361 ms 188368 KB Output is correct
90 Correct 1379 ms 188372 KB Output is correct
91 Correct 1390 ms 188372 KB Output is correct
92 Correct 1357 ms 188372 KB Output is correct
93 Correct 1366 ms 188372 KB Output is correct
94 Correct 1420 ms 188364 KB Output is correct
95 Correct 1477 ms 188372 KB Output is correct
96 Correct 1383 ms 188384 KB Output is correct
97 Correct 1370 ms 188416 KB Output is correct
98 Correct 1382 ms 188420 KB Output is correct
99 Correct 1361 ms 188408 KB Output is correct
100 Correct 847 ms 188404 KB Output is correct
101 Correct 899 ms 188396 KB Output is correct
102 Correct 820 ms 188392 KB Output is correct
103 Correct 827 ms 188388 KB Output is correct
104 Correct 836 ms 188476 KB Output is correct
105 Correct 915 ms 188388 KB Output is correct
106 Correct 912 ms 188408 KB Output is correct
107 Correct 899 ms 188408 KB Output is correct
108 Correct 926 ms 188280 KB Output is correct
109 Correct 935 ms 188420 KB Output is correct
110 Correct 1083 ms 188392 KB Output is correct
111 Correct 1075 ms 188384 KB Output is correct
112 Correct 1142 ms 188380 KB Output is correct
113 Correct 1068 ms 188388 KB Output is correct
114 Correct 1059 ms 188384 KB Output is correct
115 Correct 1080 ms 188388 KB Output is correct
116 Correct 1070 ms 188380 KB Output is correct
117 Correct 1089 ms 188372 KB Output is correct
118 Correct 1069 ms 188372 KB Output is correct
119 Correct 1058 ms 188372 KB Output is correct
120 Correct 140 ms 188352 KB Output is correct
121 Correct 143 ms 188272 KB Output is correct
122 Correct 1089 ms 188380 KB Output is correct
123 Correct 1061 ms 188376 KB Output is correct
124 Correct 1074 ms 188372 KB Output is correct
125 Correct 1108 ms 188364 KB Output is correct
126 Correct 1095 ms 188372 KB Output is correct
127 Correct 1097 ms 188492 KB Output is correct
128 Correct 1099 ms 188376 KB Output is correct
129 Correct 1119 ms 188280 KB Output is correct
130 Correct 1112 ms 188280 KB Output is correct
131 Correct 1103 ms 188280 KB Output is correct
132 Correct 1170 ms 188452 KB Output is correct
133 Correct 1128 ms 188368 KB Output is correct