답안 #888647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888647 2023-12-18T05:00:56 Z IBory Bulldozer (JOI17_bulldozer) C++17
75 / 100
696 ms 68264 KB
#include <bits/stdc++.h>
#define pii pair<ll, ll>
typedef long long ll;
using namespace std;

const int SZ = 1 << 11;
int PN[SZ], IP[SZ];

struct Point {
	ll x, y, s;
	Point(ll x = 0, ll y = 0, ll s = 0) : x(x), y(y), s(s) {};
} P[SZ];

struct Seg {
	struct Data {
		ll LS, RS, T, S;
		Data(ll LS = 0, ll RS = 0, ll T = 0, ll S = 0) : LS(LS), RS(RS), T(T), S(S) {};
		Data operator+(const Data& a) {
			Data ret;
			ret.LS = max(LS, T + a.LS);
			ret.RS = max(a.RS, RS + a.T);
			ret.S = max({S, a.S, RS + a.LS});
			ret.T = T + a.T;
			return ret;
		}
	} T[SZ << 1];

	void Update(int i, int v) {
		T[i += SZ - 1] = Data(max(0, v), max(0, v), v, max(0, v));
		while (i >>= 1) T[i] = T[i * 2] + T[i * 2 + 1];
	}

	ll Query() { return T[1].S; }
} T;

void Swap(int a, int b) {
	ll sa = P[a].s, sb = P[b].s;
	swap(IP[PN[a]], IP[PN[b]]);
	swap(PN[a], PN[b]);
	swap(P[a], P[b]);
	T.Update(a, sb);
	T.Update(b, sa);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> P[i].x >> P[i].y >> P[i].s;
		PN[i] = IP[i] = i;
	}
	
	sort(P + 1, P + N + 1, [&](Point a, Point b) {
		if (a.x != b.x) return a.x < b.x;
		return a.y < b.y;
	});
	for (int i = 1; i <= N; ++i) T.Update(i, P[i].s);

	vector<pair<pii, pii>> ord;
	for (int a = 1; a <= N; ++a) for (int b = a + 1; b <= N; ++b) {
		ll xd = P[b].x - P[a].x, yd = P[b].y - P[a].y;
		if (xd < 0) xd *= -1, yd *= -1;
		ll g = gcd(abs(xd), abs(yd)); xd /= g; yd /= g;
		if (xd == 0) yd = 1LL << 31;
		pii p = {xd, yd};
		ord.emplace_back(p, pii{a, b});
	}
	sort(ord.begin(), ord.end(), [&](pair<pii, pii>& pa, pair<pii, pii>& pb) {
		auto& [a, _1] = pa;
		auto& [b, _2] = pb;
		return a.second * b.first > a.first * b.second;
	});

	ll ans = 0;
	pii p = {-1, -1};
	for (auto& [g, _] : ord) {
		auto [a, b] = _;
		if (p != g) ans = max(ans, T.Query());
		Swap(IP[a], IP[b]);
		p = g;
	}
	ans = max(ans, T.Query());

	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 856 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 600 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 1112 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 856 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 600 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 1112 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 689 ms 68016 KB Output is correct
34 Correct 671 ms 68008 KB Output is correct
35 Correct 673 ms 67784 KB Output is correct
36 Correct 662 ms 66828 KB Output is correct
37 Correct 674 ms 66724 KB Output is correct
38 Correct 680 ms 66820 KB Output is correct
39 Correct 668 ms 66980 KB Output is correct
40 Correct 665 ms 68264 KB Output is correct
41 Correct 664 ms 68168 KB Output is correct
42 Correct 666 ms 67364 KB Output is correct
43 Correct 650 ms 67148 KB Output is correct
44 Correct 621 ms 66472 KB Output is correct
45 Correct 622 ms 68216 KB Output is correct
46 Correct 653 ms 67496 KB Output is correct
47 Correct 653 ms 67244 KB Output is correct
48 Correct 627 ms 67876 KB Output is correct
49 Correct 634 ms 68008 KB Output is correct
50 Correct 646 ms 67748 KB Output is correct
51 Correct 663 ms 67488 KB Output is correct
52 Correct 652 ms 66828 KB Output is correct
53 Correct 644 ms 66724 KB Output is correct
54 Correct 625 ms 67120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 856 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 856 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 600 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 1112 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 689 ms 68016 KB Output is correct
34 Correct 671 ms 68008 KB Output is correct
35 Correct 673 ms 67784 KB Output is correct
36 Correct 662 ms 66828 KB Output is correct
37 Correct 674 ms 66724 KB Output is correct
38 Correct 680 ms 66820 KB Output is correct
39 Correct 668 ms 66980 KB Output is correct
40 Correct 665 ms 68264 KB Output is correct
41 Correct 664 ms 68168 KB Output is correct
42 Correct 666 ms 67364 KB Output is correct
43 Correct 650 ms 67148 KB Output is correct
44 Correct 621 ms 66472 KB Output is correct
45 Correct 622 ms 68216 KB Output is correct
46 Correct 653 ms 67496 KB Output is correct
47 Correct 653 ms 67244 KB Output is correct
48 Correct 627 ms 67876 KB Output is correct
49 Correct 634 ms 68008 KB Output is correct
50 Correct 646 ms 67748 KB Output is correct
51 Correct 663 ms 67488 KB Output is correct
52 Correct 652 ms 66828 KB Output is correct
53 Correct 644 ms 66724 KB Output is correct
54 Correct 625 ms 67120 KB Output is correct
55 Correct 660 ms 68008 KB Output is correct
56 Correct 666 ms 67236 KB Output is correct
57 Correct 674 ms 67068 KB Output is correct
58 Correct 680 ms 66468 KB Output is correct
59 Correct 667 ms 67440 KB Output is correct
60 Correct 664 ms 67752 KB Output is correct
61 Correct 662 ms 66724 KB Output is correct
62 Correct 688 ms 66732 KB Output is correct
63 Correct 696 ms 67032 KB Output is correct
64 Correct 671 ms 68092 KB Output is correct
65 Correct 659 ms 67748 KB Output is correct
66 Correct 686 ms 66796 KB Output is correct
67 Correct 691 ms 67752 KB Output is correct
68 Correct 676 ms 68116 KB Output is correct
69 Correct 666 ms 67744 KB Output is correct
70 Correct 691 ms 68264 KB Output is correct
71 Correct 656 ms 66820 KB Output is correct
72 Correct 678 ms 68140 KB Output is correct
73 Correct 670 ms 67236 KB Output is correct
74 Correct 670 ms 67240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -