Submission #122701

# Submission time Handle Problem Language Result Execution time Memory
122701 2019-06-29T06:57:51 Z 이온조(#2999) Bulldozer (JOI17_bulldozer) C++14
25 / 100
2000 ms 218180 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define X first
#define Y second

inline int CCW(pii A, pii B, pii C) {
	long long tmp = 1LL*A.X*B.Y + 1LL*B.X*C.Y + 1LL*C.X*A.Y - 1LL*B.X*A.Y - 1LL*C.X*B.Y - 1LL*A.X*C.Y;
	if(tmp < 0LL) return -1;
	if(tmp == 0LL) return 0;
	if(tmp > 0LL) return +1;
}

struct myp { int x, y; };
struct info { int x, y, v; };
struct node { long long ls, rs, mx, s; };
node operator +(node L, node R) {
	node ret;
	ret.s = L.s + R.s;
	ret.ls = max(L.ls, L.s + R.ls);
	ret.rs = max(R.rs, R.s + L.rs);
	ret.mx = max({L.mx, R.mx, L.rs + R.ls, ret.s});
	return ret;
}
bool operator <(myp P, myp Q) {
	return CCW({0, 0}, {P.x, P.y}, {Q.x, Q.y}) == -1;
}
const long long INF = 1LL * 1e18;
const node MINF = {0, 0, 0, -INF};

struct segtree {
	vector<node> T;
	node get(int idx, int s, int e, int l, int r) {
		if(r < s || e < l) return MINF;
		if(l <= s && e <= r) return T[idx];
		int m = s+e >> 1;
		return get(idx*2, s, m, l, r) + get(idx*2+1, m+1, e, l, r);
	}
	void upd(int idx, int s, int e, int p, int v) {
		if(p < s || e < p) return;
		if(s == e) {
			int x = max(0, v);
			T[idx] = {x, x, x, v};
			return;
		}
		int m = s+e >> 1;
		upd(idx*2, s, m, p, v);
		upd(idx*2+1, m+1, e, p, v);
		T[idx] = T[idx*2] + T[idx*2+1];
	}
	segtree(int N) {
		T.resize(4*N);
	}
};

inline int f(int x) { return max(x, -x); }

inline int CCW(info A, info B, info C) {
	return CCW((pii){A.x, A.y}, (pii){B.x, B.y}, (pii){C.x, C.y});
}

inline pii ch(int dx, int dy) {
	if(dx == 0) dy /= f(dy);
	else if(dy == 0) dx /= f(dx);
	else {
		int gcd = __gcd(f(dx), f(dy));
		dx /= gcd; dy /= gcd;
	}
	return {dx, dy};
}

inline long long dst(pii A, pii B) {
	return 1LL * (A.X - B.X) * (A.X - B.X) + 1LL * (A.Y - B.Y) * (A.Y - B.Y);
}

vector<vector<int> > RQ[4000009];
bool chk[2009][2009];
int O[2009], R[2009];
info A[2009];

int main() {
	int N; scanf("%d",&N);
	for(int i=1; i<=N; i++) {
		scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].v);
	}
	vector<pii> S;
	for(int i=1; i<=N; i++) {
		for(int j=1; j<=N; j++) {
			int dx = A[j].x - A[i].x, dy = A[j].y - A[i].y;
			if(dx < 0 || (dx == 0 && dy <= 0)) continue;
			tie(dx, dy) = ch(dx, dy);
			S.push_back({dx, dy});
		}
	}
	vector<myp> id;
	sort(S.begin(), S.end(), [&](pii P, pii Q) { return CCW({0, 0}, P, Q) == -1; });
	for(int i=0, c=0; i<S.size(); i++) {
		if(!i || CCW({0, 0}, S[i-1], S[i]) == -1) {
			// printf("dx: %d, dy: %d\n", S[i].first, S[i].second);
			id.push_back((myp){S[i].first, S[i].second});
		}
	}
	for(int i=1; i<=N; i++) O[i] = i;
	sort(O+1, O+N+1, [&](int P, int Q) { return (pii){A[P].x, A[P].y} < (pii){A[Q].x, A[Q].y}; });
	for(int oi=1; oi<=N; oi++) {
		int i = O[oi];
		vector<int> T;
		for(int j=1; j<=N; j++) {
			int dx = A[j].x - A[i].x, dy = A[j].y - A[i].y;
			if(dx < 0 || (dx == 0 && dy <= 0)) continue;
			T.push_back(j);
		}
		sort(T.begin(), T.end(), [&](int P, int Q) {
			int ccw = CCW(A[i], A[P], A[Q]);
			if(ccw == 0) return dst({A[i].x, A[i].y}, {A[P].x, A[P].y}) < dst({A[i].x, A[i].y}, {A[Q].x, A[Q].y});
			return ccw == -1;
		});
		vector<int> P = {i}; int pr = -1, pid = -1;
		for(int j=0; j<T.size(); j++) {
			int it = T[j];
			int dx = A[it].x - A[i].x, dy = A[it].y - A[i].y;
			tie(dx, dy) = ch(dx, dy);
			int idx = lower_bound(id.begin(), id.end(), (myp){dx, dy}) - id.begin() + 1;
			if(chk[i][it]) continue;
			if(pr == -1 || CCW(A[i], A[pr], A[it]) == 0) {
				P.push_back(it);
				pr = it;
			}
			else {
				RQ[pid].push_back(P);
				for(auto& p: P) for(auto& q: P) chk[p][q] = 1;
				P = {i, it};
				pr = it;
			}
			pid = idx;
		}
		if(pid != -1) {
			RQ[pid].push_back(P);
			for(auto& p: P) for(auto& q: P) chk[p][q] = 1;
		}
	}
	segtree seg(N);
	long long ans = 0;
	for(int i=1; i<=N; i++) {
		int it = O[i];
		R[it] = i;
		seg.upd(1, 1, N, i, A[it].v);
	}
	// puts("O");
	// for(int i=1; i<=N; i++) printf("%d ",O[i]);
	// puts("");
	ans = seg.get(1, 1, N, 1, N).mx;
	for(int i=1; i<=S.size(); i++) {
		for(auto& it: RQ[i]) {
			// printf("i: %d, it: ", i);
			// for(auto& jt: it) printf("%d ", jt);
			// puts("");
			int K = it.size();
			for(int j=0; j<K; j++) seg.upd(1, 1, N, R[it[j]], A[it[K-j-1]].v);
			for(int j=0; j<K/2; j++) {
				int p = it[j], q = it[K-j-1];
				swap(O[R[p]], O[R[q]]);
				swap(R[p], R[q]);
			}
			// puts("O");
			// for(int i=1; i<=N; i++) printf("%d ",O[i]);
			// puts("");
		}
		// printf("getans: %lld\n", seg.get(1, 1, N, 1, N).mx);
		ans = max(ans, seg.get(1, 1, N, 1, N).mx);
	}
	printf("%lld", ans);
	return 0;
}

Compilation message

bulldozer.cpp: In member function 'node segtree::get(int, int, int, int, int)':
bulldozer.cpp:36:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s+e >> 1;
           ~^~
bulldozer.cpp: In member function 'void segtree::upd(int, int, int, int, int)':
bulldozer.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s+e >> 1;
           ~^~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:97:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0, c=0; i<S.size(); i++) {
                    ~^~~~~~~~~
bulldozer.cpp:97:15: warning: unused variable 'c' [-Wunused-variable]
  for(int i=0, c=0; i<S.size(); i++) {
               ^
bulldozer.cpp:119:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<T.size(); j++) {
                ~^~~~~~~~~
bulldozer.cpp:153:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<=S.size(); i++) {
               ~^~~~~~~~~~
bulldozer.cpp: In function 'int CCW(pii, pii, pii)':
bulldozer.cpp:12:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N; scanf("%d",&N);
         ~~~~~^~~~~~~~~
bulldozer.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].v);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 84 ms 94584 KB Output is correct
2 Correct 85 ms 94540 KB Output is correct
3 Correct 85 ms 94588 KB Output is correct
4 Correct 85 ms 94588 KB Output is correct
5 Correct 85 ms 94712 KB Output is correct
6 Correct 85 ms 94584 KB Output is correct
7 Correct 84 ms 94584 KB Output is correct
8 Correct 85 ms 94728 KB Output is correct
9 Correct 85 ms 94584 KB Output is correct
10 Correct 85 ms 94584 KB Output is correct
11 Correct 84 ms 94200 KB Output is correct
12 Correct 85 ms 94328 KB Output is correct
13 Correct 84 ms 94200 KB Output is correct
14 Correct 83 ms 94332 KB Output is correct
15 Correct 83 ms 94200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 94840 KB Output is correct
2 Correct 90 ms 94968 KB Output is correct
3 Correct 90 ms 94940 KB Output is correct
4 Correct 91 ms 94844 KB Output is correct
5 Correct 89 ms 94840 KB Output is correct
6 Correct 90 ms 94840 KB Output is correct
7 Correct 89 ms 94840 KB Output is correct
8 Correct 91 ms 94840 KB Output is correct
9 Correct 90 ms 94840 KB Output is correct
10 Correct 90 ms 94840 KB Output is correct
11 Correct 83 ms 94232 KB Output is correct
12 Correct 84 ms 94328 KB Output is correct
13 Correct 83 ms 94328 KB Output is correct
14 Correct 84 ms 94200 KB Output is correct
15 Correct 84 ms 94328 KB Output is correct
16 Correct 83 ms 94200 KB Output is correct
17 Correct 83 ms 94200 KB Output is correct
18 Correct 84 ms 94328 KB Output is correct
19 Correct 84 ms 94344 KB Output is correct
20 Correct 83 ms 94328 KB Output is correct
21 Correct 89 ms 94840 KB Output is correct
22 Correct 89 ms 95060 KB Output is correct
23 Correct 89 ms 94944 KB Output is correct
24 Correct 88 ms 94840 KB Output is correct
25 Correct 89 ms 94828 KB Output is correct
26 Correct 90 ms 94880 KB Output is correct
27 Correct 90 ms 94840 KB Output is correct
28 Correct 88 ms 94840 KB Output is correct
29 Correct 89 ms 94840 KB Output is correct
30 Correct 89 ms 94968 KB Output is correct
31 Correct 89 ms 95008 KB Output is correct
32 Correct 89 ms 94968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 94840 KB Output is correct
2 Correct 90 ms 94968 KB Output is correct
3 Correct 90 ms 94940 KB Output is correct
4 Correct 91 ms 94844 KB Output is correct
5 Correct 89 ms 94840 KB Output is correct
6 Correct 90 ms 94840 KB Output is correct
7 Correct 89 ms 94840 KB Output is correct
8 Correct 91 ms 94840 KB Output is correct
9 Correct 90 ms 94840 KB Output is correct
10 Correct 90 ms 94840 KB Output is correct
11 Correct 83 ms 94232 KB Output is correct
12 Correct 84 ms 94328 KB Output is correct
13 Correct 83 ms 94328 KB Output is correct
14 Correct 84 ms 94200 KB Output is correct
15 Correct 84 ms 94328 KB Output is correct
16 Correct 83 ms 94200 KB Output is correct
17 Correct 83 ms 94200 KB Output is correct
18 Correct 84 ms 94328 KB Output is correct
19 Correct 84 ms 94344 KB Output is correct
20 Correct 83 ms 94328 KB Output is correct
21 Correct 89 ms 94840 KB Output is correct
22 Correct 89 ms 95060 KB Output is correct
23 Correct 89 ms 94944 KB Output is correct
24 Correct 88 ms 94840 KB Output is correct
25 Correct 89 ms 94828 KB Output is correct
26 Correct 90 ms 94880 KB Output is correct
27 Correct 90 ms 94840 KB Output is correct
28 Correct 88 ms 94840 KB Output is correct
29 Correct 89 ms 94840 KB Output is correct
30 Correct 89 ms 94968 KB Output is correct
31 Correct 89 ms 95008 KB Output is correct
32 Correct 89 ms 94968 KB Output is correct
33 Execution timed out 2056 ms 218180 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 94840 KB Output is correct
2 Correct 90 ms 94968 KB Output is correct
3 Correct 90 ms 94940 KB Output is correct
4 Correct 91 ms 94844 KB Output is correct
5 Correct 89 ms 94840 KB Output is correct
6 Correct 90 ms 94840 KB Output is correct
7 Correct 89 ms 94840 KB Output is correct
8 Correct 91 ms 94840 KB Output is correct
9 Correct 90 ms 94840 KB Output is correct
10 Correct 90 ms 94840 KB Output is correct
11 Correct 83 ms 94232 KB Output is correct
12 Correct 84 ms 94328 KB Output is correct
13 Correct 83 ms 94328 KB Output is correct
14 Correct 84 ms 94200 KB Output is correct
15 Correct 84 ms 94328 KB Output is correct
16 Correct 83 ms 94200 KB Output is correct
17 Correct 83 ms 94200 KB Output is correct
18 Correct 84 ms 94328 KB Output is correct
19 Correct 84 ms 94344 KB Output is correct
20 Correct 83 ms 94328 KB Output is correct
21 Correct 89 ms 94840 KB Output is correct
22 Correct 89 ms 95060 KB Output is correct
23 Correct 89 ms 94944 KB Output is correct
24 Correct 88 ms 94840 KB Output is correct
25 Correct 89 ms 94828 KB Output is correct
26 Correct 90 ms 94880 KB Output is correct
27 Correct 90 ms 94840 KB Output is correct
28 Correct 88 ms 94840 KB Output is correct
29 Correct 89 ms 94840 KB Output is correct
30 Correct 89 ms 94968 KB Output is correct
31 Correct 89 ms 95008 KB Output is correct
32 Correct 89 ms 94968 KB Output is correct
33 Execution timed out 2056 ms 218180 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 94584 KB Output is correct
2 Correct 85 ms 94540 KB Output is correct
3 Correct 85 ms 94588 KB Output is correct
4 Correct 85 ms 94588 KB Output is correct
5 Correct 85 ms 94712 KB Output is correct
6 Correct 85 ms 94584 KB Output is correct
7 Correct 84 ms 94584 KB Output is correct
8 Correct 85 ms 94728 KB Output is correct
9 Correct 85 ms 94584 KB Output is correct
10 Correct 85 ms 94584 KB Output is correct
11 Correct 84 ms 94200 KB Output is correct
12 Correct 85 ms 94328 KB Output is correct
13 Correct 84 ms 94200 KB Output is correct
14 Correct 83 ms 94332 KB Output is correct
15 Correct 83 ms 94200 KB Output is correct
16 Correct 90 ms 94840 KB Output is correct
17 Correct 90 ms 94968 KB Output is correct
18 Correct 90 ms 94940 KB Output is correct
19 Correct 91 ms 94844 KB Output is correct
20 Correct 89 ms 94840 KB Output is correct
21 Correct 90 ms 94840 KB Output is correct
22 Correct 89 ms 94840 KB Output is correct
23 Correct 91 ms 94840 KB Output is correct
24 Correct 90 ms 94840 KB Output is correct
25 Correct 90 ms 94840 KB Output is correct
26 Correct 83 ms 94232 KB Output is correct
27 Correct 84 ms 94328 KB Output is correct
28 Correct 83 ms 94328 KB Output is correct
29 Correct 84 ms 94200 KB Output is correct
30 Correct 84 ms 94328 KB Output is correct
31 Correct 83 ms 94200 KB Output is correct
32 Correct 83 ms 94200 KB Output is correct
33 Correct 84 ms 94328 KB Output is correct
34 Correct 84 ms 94344 KB Output is correct
35 Correct 83 ms 94328 KB Output is correct
36 Correct 89 ms 94840 KB Output is correct
37 Correct 89 ms 95060 KB Output is correct
38 Correct 89 ms 94944 KB Output is correct
39 Correct 88 ms 94840 KB Output is correct
40 Correct 89 ms 94828 KB Output is correct
41 Correct 90 ms 94880 KB Output is correct
42 Correct 90 ms 94840 KB Output is correct
43 Correct 88 ms 94840 KB Output is correct
44 Correct 89 ms 94840 KB Output is correct
45 Correct 89 ms 94968 KB Output is correct
46 Correct 89 ms 95008 KB Output is correct
47 Correct 89 ms 94968 KB Output is correct
48 Execution timed out 2056 ms 218180 KB Time limit exceeded
49 Halted 0 ms 0 KB -