Submission #114989

# Submission time Handle Problem Language Result Execution time Memory
114989 2019-06-04T10:08:09 Z imyujin Bulldozer (JOI17_bulldozer) C++14
80 / 100
1387 ms 16476 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];
pint nd;
long long seg[4*MAXN][4];
int s[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<dn; i++) printf("%d %d\n", degree[i].fi, degree[i].se);

	for(int i=0; i<N; i++) point[i]=i;
	nd=degree[0];
	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];
	
	//printf("%d\n", N);

	for(int i=0; i<dn;){
		/*
		for(int j=0; j<N; j++) printf("%d ", point[j]);
		printf("\n");
		*/
		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];
		}
		/*
		for(int j=0; j<sn; j++) printf("*%d", point[s[j]]);
		printf("\n");
		*/

		nd=degree[i];
		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(nd, point[s[j+k]])==distance(nd, 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:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
bulldozer.cpp:95: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);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 3 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 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 16 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 4 ms 384 KB Output is correct
8 Correct 4 ms 356 KB Output is correct
9 Correct 4 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 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 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 16 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 4 ms 384 KB Output is correct
8 Correct 4 ms 356 KB Output is correct
9 Correct 4 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 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 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 1285 ms 16260 KB Output is correct
34 Correct 1294 ms 16252 KB Output is correct
35 Correct 1260 ms 16248 KB Output is correct
36 Correct 1250 ms 16352 KB Output is correct
37 Correct 1247 ms 16260 KB Output is correct
38 Correct 1238 ms 16248 KB Output is correct
39 Correct 1237 ms 16248 KB Output is correct
40 Correct 1239 ms 16356 KB Output is correct
41 Correct 1303 ms 16248 KB Output is correct
42 Correct 1293 ms 16412 KB Output is correct
43 Correct 1166 ms 16356 KB Output is correct
44 Correct 1159 ms 16356 KB Output is correct
45 Correct 1186 ms 16352 KB Output is correct
46 Correct 1184 ms 16356 KB Output is correct
47 Correct 1149 ms 16284 KB Output is correct
48 Correct 1151 ms 16260 KB Output is correct
49 Correct 1130 ms 16376 KB Output is correct
50 Correct 1111 ms 16476 KB Output is correct
51 Correct 1142 ms 16248 KB Output is correct
52 Correct 1174 ms 16376 KB Output is correct
53 Correct 1165 ms 16256 KB Output is correct
54 Correct 1129 ms 16244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 16 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 4 ms 384 KB Output is correct
8 Correct 4 ms 356 KB Output is correct
9 Correct 4 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 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 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 1285 ms 16260 KB Output is correct
34 Correct 1294 ms 16252 KB Output is correct
35 Correct 1260 ms 16248 KB Output is correct
36 Correct 1250 ms 16352 KB Output is correct
37 Correct 1247 ms 16260 KB Output is correct
38 Correct 1238 ms 16248 KB Output is correct
39 Correct 1237 ms 16248 KB Output is correct
40 Correct 1239 ms 16356 KB Output is correct
41 Correct 1303 ms 16248 KB Output is correct
42 Correct 1293 ms 16412 KB Output is correct
43 Correct 1166 ms 16356 KB Output is correct
44 Correct 1159 ms 16356 KB Output is correct
45 Correct 1186 ms 16352 KB Output is correct
46 Correct 1184 ms 16356 KB Output is correct
47 Correct 1149 ms 16284 KB Output is correct
48 Correct 1151 ms 16260 KB Output is correct
49 Correct 1130 ms 16376 KB Output is correct
50 Correct 1111 ms 16476 KB Output is correct
51 Correct 1142 ms 16248 KB Output is correct
52 Correct 1174 ms 16376 KB Output is correct
53 Correct 1165 ms 16256 KB Output is correct
54 Correct 1129 ms 16244 KB Output is correct
55 Correct 1279 ms 16248 KB Output is correct
56 Correct 1239 ms 16352 KB Output is correct
57 Correct 1257 ms 16248 KB Output is correct
58 Correct 1287 ms 16248 KB Output is correct
59 Correct 1263 ms 16352 KB Output is correct
60 Correct 1285 ms 16264 KB Output is correct
61 Correct 1334 ms 16252 KB Output is correct
62 Correct 1292 ms 16248 KB Output is correct
63 Correct 1294 ms 16248 KB Output is correct
64 Correct 1333 ms 16352 KB Output is correct
65 Correct 1264 ms 16236 KB Output is correct
66 Correct 1249 ms 16348 KB Output is correct
67 Correct 1329 ms 16388 KB Output is correct
68 Correct 1237 ms 16248 KB Output is correct
69 Correct 1247 ms 16360 KB Output is correct
70 Correct 1253 ms 16384 KB Output is correct
71 Correct 1305 ms 16248 KB Output is correct
72 Correct 1301 ms 16384 KB Output is correct
73 Correct 1289 ms 16248 KB Output is correct
74 Correct 1312 ms 16376 KB Output is correct
# Verdict Execution time Memory 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 3 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 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 16 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 4 ms 384 KB Output is correct
23 Correct 4 ms 356 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 3 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 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 1285 ms 16260 KB Output is correct
49 Correct 1294 ms 16252 KB Output is correct
50 Correct 1260 ms 16248 KB Output is correct
51 Correct 1250 ms 16352 KB Output is correct
52 Correct 1247 ms 16260 KB Output is correct
53 Correct 1238 ms 16248 KB Output is correct
54 Correct 1237 ms 16248 KB Output is correct
55 Correct 1239 ms 16356 KB Output is correct
56 Correct 1303 ms 16248 KB Output is correct
57 Correct 1293 ms 16412 KB Output is correct
58 Correct 1166 ms 16356 KB Output is correct
59 Correct 1159 ms 16356 KB Output is correct
60 Correct 1186 ms 16352 KB Output is correct
61 Correct 1184 ms 16356 KB Output is correct
62 Correct 1149 ms 16284 KB Output is correct
63 Correct 1151 ms 16260 KB Output is correct
64 Correct 1130 ms 16376 KB Output is correct
65 Correct 1111 ms 16476 KB Output is correct
66 Correct 1142 ms 16248 KB Output is correct
67 Correct 1174 ms 16376 KB Output is correct
68 Correct 1165 ms 16256 KB Output is correct
69 Correct 1129 ms 16244 KB Output is correct
70 Correct 1279 ms 16248 KB Output is correct
71 Correct 1239 ms 16352 KB Output is correct
72 Correct 1257 ms 16248 KB Output is correct
73 Correct 1287 ms 16248 KB Output is correct
74 Correct 1263 ms 16352 KB Output is correct
75 Correct 1285 ms 16264 KB Output is correct
76 Correct 1334 ms 16252 KB Output is correct
77 Correct 1292 ms 16248 KB Output is correct
78 Correct 1294 ms 16248 KB Output is correct
79 Correct 1333 ms 16352 KB Output is correct
80 Correct 1264 ms 16236 KB Output is correct
81 Correct 1249 ms 16348 KB Output is correct
82 Correct 1329 ms 16388 KB Output is correct
83 Correct 1237 ms 16248 KB Output is correct
84 Correct 1247 ms 16360 KB Output is correct
85 Correct 1253 ms 16384 KB Output is correct
86 Correct 1305 ms 16248 KB Output is correct
87 Correct 1301 ms 16384 KB Output is correct
88 Correct 1289 ms 16248 KB Output is correct
89 Correct 1312 ms 16376 KB Output is correct
90 Correct 1300 ms 16356 KB Output is correct
91 Correct 1351 ms 16276 KB Output is correct
92 Correct 1350 ms 16368 KB Output is correct
93 Correct 1321 ms 16376 KB Output is correct
94 Correct 1324 ms 16260 KB Output is correct
95 Correct 1387 ms 16292 KB Output is correct
96 Correct 1254 ms 16244 KB Output is correct
97 Correct 1255 ms 16248 KB Output is correct
98 Correct 1249 ms 16248 KB Output is correct
99 Correct 1280 ms 16236 KB Output is correct
100 Incorrect 549 ms 16248 KB Output isn't correct
101 Halted 0 ms 0 KB -