답안 #122655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122655 2019-06-29T04:32:28 Z 임유진(#2862) Bulldozer (JOI17_bulldozer) C++14
100 / 100
1595 ms 24156 KB
#include<stdio.h>
#include<algorithm>

using namespace std;

#define MAXN 2005
#define fi first
#define se second

typedef pair<int, int> pint;

long long X[MAXN], Y[MAXN], W[MAXN];
pint degree[MAXN*MAXN];
int dn;
int point[MAXN], pidx[MAXN];
long long seg[4*MAXN][4];
int s[MAXN*MAXN], sn;

long long distance(pint d, int p){
	long long dx=X[d.fi]-X[d.se], dy=Y[d.fi]-Y[d.se];
	if(dx<0){
		dx*=-1;
		dy*=-1;
	}
	else if(dx==0) dy=1;

	return dy*X[p]-dx*Y[p];
}

long long degdif(pint a, pint b){
	long long dx1=X[a.fi]-X[a.se], dy1=Y[a.fi]-Y[a.se], dx2=X[b.fi]-X[b.se], dy2=Y[b.fi]-Y[b.se];
	if(dx1<0){
		dx1*=-1;
		dy1*=-1;
	}
	else if(dx1==0) dy1=1;
	if(dx2<0){
		dx2*=-1;
		dy2*=-1;
	}
	else if(dx2==0) dy2=1;
	return dy1*dx2-dx1*dy2;
}

bool cmpdeg(pint a, pint b){
	return degdif(a, b)>0;
}

bool cmppoint(int a, int b){
	return X[a]!=X[b] ? X[a]<X[b] : Y[a]<Y[b];
}

long long gmax(long long a, long long b){
	return a>b?a:b;
}

void mkseg(int idx, int l, int r){
	if(l==r){
		seg[idx][0]=W[point[l]];
		seg[idx][1]=seg[idx][2]=seg[idx][3]=gmax(W[point[l]], 0);
	}
	else{
		int m=(l+r)/2;
		mkseg(idx*2, l, m);
		mkseg(idx*2+1, m+1, r);
		seg[idx][0]=seg[idx*2][0]+seg[idx*2+1][0];
		seg[idx][1]=gmax(seg[idx*2][3]+seg[idx*2+1][2], gmax(seg[idx*2][1], seg[idx*2+1][1]));
		seg[idx][2]=gmax(seg[idx*2][2], seg[idx*2][0]+seg[idx*2+1][2]);
		seg[idx][3]=gmax(seg[idx*2+1][3], seg[idx*2][3]+seg[idx*2+1][0]);
	}
}

void updseg(int idx, int l, int r, int c){
	if(l==r){
		seg[idx][0]=W[point[l]];
		seg[idx][1]=seg[idx][2]=seg[idx][3]=gmax(W[point[l]], 0);
	}
	else{
		int m=(l+r)/2;
		if(c<=m) updseg(idx*2, l, m, c);
		else updseg(idx*2+1, m+1, r, c);
		seg[idx][0]=seg[idx*2][0]+seg[idx*2+1][0];
		seg[idx][1]=gmax(seg[idx*2][3]+seg[idx*2+1][2], gmax(seg[idx*2][1], seg[idx*2+1][1]));
		seg[idx][2]=gmax(seg[idx*2][2], seg[idx*2][0]+seg[idx*2+1][2]);
		seg[idx][3]=gmax(seg[idx*2+1][3], seg[idx*2][3]+seg[idx*2+1][0]);
	}
}

int main(){
	int N;
	long long ans;
	
	scanf("%d", &N);
	for(int i=0; i<N; i++) scanf("%lld%lld%lld", X+i, Y+i, W+i);
	
	for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) degree[dn++]=make_pair(i, j);
	sort(degree, degree+dn, cmpdeg);

	for(int i=0; i<N; i++) point[i]=i;
	sort(point, point+N, cmppoint);
	for(int i=0; i<N; i++) pidx[point[i]]=i;
	mkseg(1, 0, N-1);
	ans=seg[1][1];

	for(int i=0; i<dn;){
		sn=0;
		for(int j=i; j<dn&&degdif(degree[j], degree[i])==0; j++){
			s[sn++]=pidx[degree[j].fi];
			s[sn++]=pidx[degree[j].se];
		}

		sort(s, s+sn);
		sn=unique(s, s+sn)-s;
		for(int j=0; j<sn;){
			int k;
			for(k=0; j+k<sn&&distance(degree[i], point[s[j+k]])==distance(degree[i], point[s[j]]); k++);
			for(int l=0; l<k/2; l++){
				int t=point[s[j+l]];
				point[s[j+l]]=point[s[j+k-1-l]];
				point[s[j+k-1-l]]=t;
			}
			j+=k;
		}
		for(int j=0; j<sn; j++){
			pidx[point[s[j]]]=s[j];
			updseg(1, 0, N-1, s[j]);
		}

		ans=gmax(ans, seg[1][1]);
		for(i++; i<dn&&degdif(degree[i], degree[i-1])==0; i++);
	}

	printf("%lld", ans);
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
bulldozer.cpp:94:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<N; i++) scanf("%lld%lld%lld", X+i, Y+i, W+i);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 380 KB Output is correct
4 Correct 4 ms 380 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 4 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 4 ms 376 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 4 ms 380 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 380 KB Output is correct
4 Correct 4 ms 380 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 4 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 4 ms 376 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 4 ms 380 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 1562 ms 16256 KB Output is correct
34 Correct 1568 ms 16144 KB Output is correct
35 Correct 1557 ms 16268 KB Output is correct
36 Correct 1555 ms 16248 KB Output is correct
37 Correct 1553 ms 16368 KB Output is correct
38 Correct 1545 ms 16252 KB Output is correct
39 Correct 1543 ms 16232 KB Output is correct
40 Correct 1560 ms 16276 KB Output is correct
41 Correct 1555 ms 16260 KB Output is correct
42 Correct 1558 ms 16348 KB Output is correct
43 Correct 1403 ms 16376 KB Output is correct
44 Correct 1394 ms 16268 KB Output is correct
45 Correct 1394 ms 16348 KB Output is correct
46 Correct 1398 ms 16348 KB Output is correct
47 Correct 1388 ms 16376 KB Output is correct
48 Correct 1428 ms 16264 KB Output is correct
49 Correct 1396 ms 16252 KB Output is correct
50 Correct 1386 ms 16364 KB Output is correct
51 Correct 1392 ms 16256 KB Output is correct
52 Correct 1405 ms 16376 KB Output is correct
53 Correct 1402 ms 16248 KB Output is correct
54 Correct 1394 ms 16228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 380 KB Output is correct
4 Correct 4 ms 380 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 4 ms 376 KB Output is correct
27 Correct 4 ms 376 KB Output is correct
28 Correct 4 ms 376 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 4 ms 380 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 1562 ms 16256 KB Output is correct
34 Correct 1568 ms 16144 KB Output is correct
35 Correct 1557 ms 16268 KB Output is correct
36 Correct 1555 ms 16248 KB Output is correct
37 Correct 1553 ms 16368 KB Output is correct
38 Correct 1545 ms 16252 KB Output is correct
39 Correct 1543 ms 16232 KB Output is correct
40 Correct 1560 ms 16276 KB Output is correct
41 Correct 1555 ms 16260 KB Output is correct
42 Correct 1558 ms 16348 KB Output is correct
43 Correct 1403 ms 16376 KB Output is correct
44 Correct 1394 ms 16268 KB Output is correct
45 Correct 1394 ms 16348 KB Output is correct
46 Correct 1398 ms 16348 KB Output is correct
47 Correct 1388 ms 16376 KB Output is correct
48 Correct 1428 ms 16264 KB Output is correct
49 Correct 1396 ms 16252 KB Output is correct
50 Correct 1386 ms 16364 KB Output is correct
51 Correct 1392 ms 16256 KB Output is correct
52 Correct 1405 ms 16376 KB Output is correct
53 Correct 1402 ms 16248 KB Output is correct
54 Correct 1394 ms 16228 KB Output is correct
55 Correct 1570 ms 16244 KB Output is correct
56 Correct 1548 ms 16264 KB Output is correct
57 Correct 1562 ms 16348 KB Output is correct
58 Correct 1546 ms 16376 KB Output is correct
59 Correct 1559 ms 16348 KB Output is correct
60 Correct 1546 ms 16360 KB Output is correct
61 Correct 1554 ms 16296 KB Output is correct
62 Correct 1552 ms 16476 KB Output is correct
63 Correct 1560 ms 16376 KB Output is correct
64 Correct 1560 ms 16364 KB Output is correct
65 Correct 1554 ms 16264 KB Output is correct
66 Correct 1546 ms 16268 KB Output is correct
67 Correct 1534 ms 16232 KB Output is correct
68 Correct 1545 ms 16248 KB Output is correct
69 Correct 1554 ms 16276 KB Output is correct
70 Correct 1554 ms 16372 KB Output is correct
71 Correct 1545 ms 16368 KB Output is correct
72 Correct 1550 ms 16268 KB Output is correct
73 Correct 1541 ms 16236 KB Output is correct
74 Correct 1547 ms 16268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 4 ms 380 KB Output is correct
19 Correct 4 ms 380 KB Output is correct
20 Correct 4 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 276 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 4 ms 376 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 4 ms 376 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 4 ms 376 KB Output is correct
42 Correct 4 ms 376 KB Output is correct
43 Correct 4 ms 376 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 4 ms 380 KB Output is correct
47 Correct 4 ms 376 KB Output is correct
48 Correct 1562 ms 16256 KB Output is correct
49 Correct 1568 ms 16144 KB Output is correct
50 Correct 1557 ms 16268 KB Output is correct
51 Correct 1555 ms 16248 KB Output is correct
52 Correct 1553 ms 16368 KB Output is correct
53 Correct 1545 ms 16252 KB Output is correct
54 Correct 1543 ms 16232 KB Output is correct
55 Correct 1560 ms 16276 KB Output is correct
56 Correct 1555 ms 16260 KB Output is correct
57 Correct 1558 ms 16348 KB Output is correct
58 Correct 1403 ms 16376 KB Output is correct
59 Correct 1394 ms 16268 KB Output is correct
60 Correct 1394 ms 16348 KB Output is correct
61 Correct 1398 ms 16348 KB Output is correct
62 Correct 1388 ms 16376 KB Output is correct
63 Correct 1428 ms 16264 KB Output is correct
64 Correct 1396 ms 16252 KB Output is correct
65 Correct 1386 ms 16364 KB Output is correct
66 Correct 1392 ms 16256 KB Output is correct
67 Correct 1405 ms 16376 KB Output is correct
68 Correct 1402 ms 16248 KB Output is correct
69 Correct 1394 ms 16228 KB Output is correct
70 Correct 1570 ms 16244 KB Output is correct
71 Correct 1548 ms 16264 KB Output is correct
72 Correct 1562 ms 16348 KB Output is correct
73 Correct 1546 ms 16376 KB Output is correct
74 Correct 1559 ms 16348 KB Output is correct
75 Correct 1546 ms 16360 KB Output is correct
76 Correct 1554 ms 16296 KB Output is correct
77 Correct 1552 ms 16476 KB Output is correct
78 Correct 1560 ms 16376 KB Output is correct
79 Correct 1560 ms 16364 KB Output is correct
80 Correct 1554 ms 16264 KB Output is correct
81 Correct 1546 ms 16268 KB Output is correct
82 Correct 1534 ms 16232 KB Output is correct
83 Correct 1545 ms 16248 KB Output is correct
84 Correct 1554 ms 16276 KB Output is correct
85 Correct 1554 ms 16372 KB Output is correct
86 Correct 1545 ms 16368 KB Output is correct
87 Correct 1550 ms 16268 KB Output is correct
88 Correct 1541 ms 16236 KB Output is correct
89 Correct 1547 ms 16268 KB Output is correct
90 Correct 1577 ms 16236 KB Output is correct
91 Correct 1557 ms 16264 KB Output is correct
92 Correct 1595 ms 16476 KB Output is correct
93 Correct 1558 ms 16368 KB Output is correct
94 Correct 1573 ms 16476 KB Output is correct
95 Correct 1564 ms 16240 KB Output is correct
96 Correct 1554 ms 16364 KB Output is correct
97 Correct 1549 ms 16376 KB Output is correct
98 Correct 1550 ms 16248 KB Output is correct
99 Correct 1554 ms 16252 KB Output is correct
100 Correct 1031 ms 24056 KB Output is correct
101 Correct 1033 ms 24036 KB Output is correct
102 Correct 1035 ms 24156 KB Output is correct
103 Correct 1033 ms 24156 KB Output is correct
104 Correct 1022 ms 24152 KB Output is correct
105 Correct 1199 ms 21464 KB Output is correct
106 Correct 1204 ms 21368 KB Output is correct
107 Correct 1206 ms 21496 KB Output is correct
108 Correct 1209 ms 21368 KB Output is correct
109 Correct 1215 ms 21496 KB Output is correct
110 Correct 991 ms 16512 KB Output is correct
111 Correct 1014 ms 16508 KB Output is correct
112 Correct 1016 ms 16600 KB Output is correct
113 Correct 999 ms 16632 KB Output is correct
114 Correct 990 ms 16604 KB Output is correct
115 Correct 989 ms 16504 KB Output is correct
116 Correct 992 ms 16632 KB Output is correct
117 Correct 1030 ms 16596 KB Output is correct
118 Correct 1000 ms 16504 KB Output is correct
119 Correct 990 ms 16512 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 376 KB Output is correct
122 Correct 1396 ms 16400 KB Output is correct
123 Correct 1399 ms 16376 KB Output is correct
124 Correct 1401 ms 16420 KB Output is correct
125 Correct 1395 ms 16268 KB Output is correct
126 Correct 1402 ms 16248 KB Output is correct
127 Correct 1396 ms 16372 KB Output is correct
128 Correct 1413 ms 16236 KB Output is correct
129 Correct 1395 ms 16360 KB Output is correct
130 Correct 1408 ms 16376 KB Output is correct
131 Correct 1412 ms 16476 KB Output is correct
132 Correct 1403 ms 16476 KB Output is correct
133 Correct 1396 ms 16360 KB Output is correct