답안 #115399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115399 2019-06-07T07:10:36 Z imyujin Bulldozer (JOI17_bulldozer) C++14
100 / 100
1407 ms 24184 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 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 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 3 ms 384 KB Output is correct
15 Correct 3 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 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 6 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 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 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 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 432 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 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 6 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 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 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 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 432 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1319 ms 16260 KB Output is correct
34 Correct 1377 ms 16248 KB Output is correct
35 Correct 1393 ms 16232 KB Output is correct
36 Correct 1367 ms 16344 KB Output is correct
37 Correct 1296 ms 16216 KB Output is correct
38 Correct 1264 ms 16216 KB Output is correct
39 Correct 1271 ms 16344 KB Output is correct
40 Correct 1359 ms 16456 KB Output is correct
41 Correct 1357 ms 16348 KB Output is correct
42 Correct 1350 ms 16256 KB Output is correct
43 Correct 1198 ms 16404 KB Output is correct
44 Correct 1204 ms 16248 KB Output is correct
45 Correct 1196 ms 16376 KB Output is correct
46 Correct 1259 ms 16272 KB Output is correct
47 Correct 1175 ms 16376 KB Output is correct
48 Correct 1141 ms 16396 KB Output is correct
49 Correct 1214 ms 16376 KB Output is correct
50 Correct 1121 ms 16216 KB Output is correct
51 Correct 1117 ms 16340 KB Output is correct
52 Correct 1214 ms 16360 KB Output is correct
53 Correct 1188 ms 16376 KB Output is correct
54 Correct 1178 ms 16236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 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 6 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 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 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 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 432 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1319 ms 16260 KB Output is correct
34 Correct 1377 ms 16248 KB Output is correct
35 Correct 1393 ms 16232 KB Output is correct
36 Correct 1367 ms 16344 KB Output is correct
37 Correct 1296 ms 16216 KB Output is correct
38 Correct 1264 ms 16216 KB Output is correct
39 Correct 1271 ms 16344 KB Output is correct
40 Correct 1359 ms 16456 KB Output is correct
41 Correct 1357 ms 16348 KB Output is correct
42 Correct 1350 ms 16256 KB Output is correct
43 Correct 1198 ms 16404 KB Output is correct
44 Correct 1204 ms 16248 KB Output is correct
45 Correct 1196 ms 16376 KB Output is correct
46 Correct 1259 ms 16272 KB Output is correct
47 Correct 1175 ms 16376 KB Output is correct
48 Correct 1141 ms 16396 KB Output is correct
49 Correct 1214 ms 16376 KB Output is correct
50 Correct 1121 ms 16216 KB Output is correct
51 Correct 1117 ms 16340 KB Output is correct
52 Correct 1214 ms 16360 KB Output is correct
53 Correct 1188 ms 16376 KB Output is correct
54 Correct 1178 ms 16236 KB Output is correct
55 Correct 1317 ms 16344 KB Output is correct
56 Correct 1345 ms 16236 KB Output is correct
57 Correct 1354 ms 16344 KB Output is correct
58 Correct 1346 ms 16248 KB Output is correct
59 Correct 1407 ms 16376 KB Output is correct
60 Correct 1327 ms 16252 KB Output is correct
61 Correct 1335 ms 16376 KB Output is correct
62 Correct 1375 ms 16380 KB Output is correct
63 Correct 1284 ms 16248 KB Output is correct
64 Correct 1404 ms 16376 KB Output is correct
65 Correct 1351 ms 16376 KB Output is correct
66 Correct 1259 ms 16248 KB Output is correct
67 Correct 1309 ms 16376 KB Output is correct
68 Correct 1281 ms 16248 KB Output is correct
69 Correct 1349 ms 16248 KB Output is correct
70 Correct 1350 ms 16376 KB Output is correct
71 Correct 1341 ms 16376 KB Output is correct
72 Correct 1340 ms 16248 KB Output is correct
73 Correct 1330 ms 16248 KB Output is correct
74 Correct 1352 ms 16248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 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 3 ms 384 KB Output is correct
15 Correct 3 ms 432 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 4 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 3 ms 384 KB Output is correct
34 Correct 2 ms 256 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 384 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 5 ms 432 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 6 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 1319 ms 16260 KB Output is correct
49 Correct 1377 ms 16248 KB Output is correct
50 Correct 1393 ms 16232 KB Output is correct
51 Correct 1367 ms 16344 KB Output is correct
52 Correct 1296 ms 16216 KB Output is correct
53 Correct 1264 ms 16216 KB Output is correct
54 Correct 1271 ms 16344 KB Output is correct
55 Correct 1359 ms 16456 KB Output is correct
56 Correct 1357 ms 16348 KB Output is correct
57 Correct 1350 ms 16256 KB Output is correct
58 Correct 1198 ms 16404 KB Output is correct
59 Correct 1204 ms 16248 KB Output is correct
60 Correct 1196 ms 16376 KB Output is correct
61 Correct 1259 ms 16272 KB Output is correct
62 Correct 1175 ms 16376 KB Output is correct
63 Correct 1141 ms 16396 KB Output is correct
64 Correct 1214 ms 16376 KB Output is correct
65 Correct 1121 ms 16216 KB Output is correct
66 Correct 1117 ms 16340 KB Output is correct
67 Correct 1214 ms 16360 KB Output is correct
68 Correct 1188 ms 16376 KB Output is correct
69 Correct 1178 ms 16236 KB Output is correct
70 Correct 1317 ms 16344 KB Output is correct
71 Correct 1345 ms 16236 KB Output is correct
72 Correct 1354 ms 16344 KB Output is correct
73 Correct 1346 ms 16248 KB Output is correct
74 Correct 1407 ms 16376 KB Output is correct
75 Correct 1327 ms 16252 KB Output is correct
76 Correct 1335 ms 16376 KB Output is correct
77 Correct 1375 ms 16380 KB Output is correct
78 Correct 1284 ms 16248 KB Output is correct
79 Correct 1404 ms 16376 KB Output is correct
80 Correct 1351 ms 16376 KB Output is correct
81 Correct 1259 ms 16248 KB Output is correct
82 Correct 1309 ms 16376 KB Output is correct
83 Correct 1281 ms 16248 KB Output is correct
84 Correct 1349 ms 16248 KB Output is correct
85 Correct 1350 ms 16376 KB Output is correct
86 Correct 1341 ms 16376 KB Output is correct
87 Correct 1340 ms 16248 KB Output is correct
88 Correct 1330 ms 16248 KB Output is correct
89 Correct 1352 ms 16248 KB Output is correct
90 Correct 1367 ms 16344 KB Output is correct
91 Correct 1369 ms 16352 KB Output is correct
92 Correct 1336 ms 16248 KB Output is correct
93 Correct 1355 ms 16220 KB Output is correct
94 Correct 1345 ms 16376 KB Output is correct
95 Correct 1244 ms 16376 KB Output is correct
96 Correct 1244 ms 16248 KB Output is correct
97 Correct 1310 ms 16268 KB Output is correct
98 Correct 1330 ms 16232 KB Output is correct
99 Correct 1358 ms 16248 KB Output is correct
100 Correct 886 ms 24140 KB Output is correct
101 Correct 847 ms 24056 KB Output is correct
102 Correct 868 ms 24056 KB Output is correct
103 Correct 874 ms 24184 KB Output is correct
104 Correct 876 ms 24168 KB Output is correct
105 Correct 1016 ms 21368 KB Output is correct
106 Correct 1066 ms 21496 KB Output is correct
107 Correct 1064 ms 21416 KB Output is correct
108 Correct 1031 ms 21436 KB Output is correct
109 Correct 1029 ms 21420 KB Output is correct
110 Correct 805 ms 16564 KB Output is correct
111 Correct 829 ms 16508 KB Output is correct
112 Correct 827 ms 16476 KB Output is correct
113 Correct 868 ms 16376 KB Output is correct
114 Correct 799 ms 16508 KB Output is correct
115 Correct 808 ms 16504 KB Output is correct
116 Correct 824 ms 16476 KB Output is correct
117 Correct 798 ms 16472 KB Output is correct
118 Correct 848 ms 16504 KB Output is correct
119 Correct 895 ms 16504 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 1258 ms 16264 KB Output is correct
123 Correct 1166 ms 16248 KB Output is correct
124 Correct 1149 ms 16248 KB Output is correct
125 Correct 1129 ms 16232 KB Output is correct
126 Correct 1194 ms 16248 KB Output is correct
127 Correct 1203 ms 16248 KB Output is correct
128 Correct 1263 ms 16376 KB Output is correct
129 Correct 1329 ms 16224 KB Output is correct
130 Correct 1208 ms 16248 KB Output is correct
131 Correct 1211 ms 16280 KB Output is correct
132 Correct 1202 ms 16348 KB Output is correct
133 Correct 1250 ms 16248 KB Output is correct