답안 #888658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888658 2023-12-18T05:07:58 Z IBory Bulldozer (JOI17_bulldozer) C++17
100 / 100
730 ms 68520 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, p1] = pa;
		auto& [b, p2] = pb;
		if (a.second * b.first != a.first * b.second) return a.second * b.first > a.first * b.second;
		return p1 < p2;
	});

	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 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 920 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 860 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 600 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 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 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 856 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 860 KB Output is correct
3 Correct 2 ms 920 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 860 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 600 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 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 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 856 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 730 ms 68404 KB Output is correct
34 Correct 679 ms 66984 KB Output is correct
35 Correct 695 ms 67464 KB Output is correct
36 Correct 675 ms 67492 KB Output is correct
37 Correct 689 ms 68004 KB Output is correct
38 Correct 679 ms 67020 KB Output is correct
39 Correct 680 ms 67516 KB Output is correct
40 Correct 686 ms 66688 KB Output is correct
41 Correct 672 ms 68004 KB Output is correct
42 Correct 674 ms 66724 KB Output is correct
43 Correct 665 ms 67616 KB Output is correct
44 Correct 631 ms 67780 KB Output is correct
45 Correct 630 ms 68136 KB Output is correct
46 Correct 665 ms 66984 KB Output is correct
47 Correct 672 ms 67524 KB Output is correct
48 Correct 638 ms 68268 KB Output is correct
49 Correct 643 ms 66488 KB Output is correct
50 Correct 670 ms 66988 KB Output is correct
51 Correct 660 ms 67844 KB Output is correct
52 Correct 658 ms 67692 KB Output is correct
53 Correct 655 ms 67672 KB Output is correct
54 Correct 646 ms 68264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 920 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 860 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 600 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 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 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 856 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 730 ms 68404 KB Output is correct
34 Correct 679 ms 66984 KB Output is correct
35 Correct 695 ms 67464 KB Output is correct
36 Correct 675 ms 67492 KB Output is correct
37 Correct 689 ms 68004 KB Output is correct
38 Correct 679 ms 67020 KB Output is correct
39 Correct 680 ms 67516 KB Output is correct
40 Correct 686 ms 66688 KB Output is correct
41 Correct 672 ms 68004 KB Output is correct
42 Correct 674 ms 66724 KB Output is correct
43 Correct 665 ms 67616 KB Output is correct
44 Correct 631 ms 67780 KB Output is correct
45 Correct 630 ms 68136 KB Output is correct
46 Correct 665 ms 66984 KB Output is correct
47 Correct 672 ms 67524 KB Output is correct
48 Correct 638 ms 68268 KB Output is correct
49 Correct 643 ms 66488 KB Output is correct
50 Correct 670 ms 66988 KB Output is correct
51 Correct 660 ms 67844 KB Output is correct
52 Correct 658 ms 67692 KB Output is correct
53 Correct 655 ms 67672 KB Output is correct
54 Correct 646 ms 68264 KB Output is correct
55 Correct 671 ms 68008 KB Output is correct
56 Correct 671 ms 67904 KB Output is correct
57 Correct 684 ms 66988 KB Output is correct
58 Correct 683 ms 66728 KB Output is correct
59 Correct 690 ms 67876 KB Output is correct
60 Correct 672 ms 66472 KB Output is correct
61 Correct 669 ms 68264 KB Output is correct
62 Correct 715 ms 66824 KB Output is correct
63 Correct 682 ms 66560 KB Output is correct
64 Correct 677 ms 66984 KB Output is correct
65 Correct 664 ms 66728 KB Output is correct
66 Correct 673 ms 68044 KB Output is correct
67 Correct 680 ms 67136 KB Output is correct
68 Correct 695 ms 66756 KB Output is correct
69 Correct 676 ms 67492 KB Output is correct
70 Correct 677 ms 67496 KB Output is correct
71 Correct 680 ms 66468 KB Output is correct
72 Correct 692 ms 68520 KB Output is correct
73 Correct 684 ms 66724 KB Output is correct
74 Correct 676 ms 68184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 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 2 ms 856 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 920 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 860 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 860 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 856 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 730 ms 68404 KB Output is correct
49 Correct 679 ms 66984 KB Output is correct
50 Correct 695 ms 67464 KB Output is correct
51 Correct 675 ms 67492 KB Output is correct
52 Correct 689 ms 68004 KB Output is correct
53 Correct 679 ms 67020 KB Output is correct
54 Correct 680 ms 67516 KB Output is correct
55 Correct 686 ms 66688 KB Output is correct
56 Correct 672 ms 68004 KB Output is correct
57 Correct 674 ms 66724 KB Output is correct
58 Correct 665 ms 67616 KB Output is correct
59 Correct 631 ms 67780 KB Output is correct
60 Correct 630 ms 68136 KB Output is correct
61 Correct 665 ms 66984 KB Output is correct
62 Correct 672 ms 67524 KB Output is correct
63 Correct 638 ms 68268 KB Output is correct
64 Correct 643 ms 66488 KB Output is correct
65 Correct 670 ms 66988 KB Output is correct
66 Correct 660 ms 67844 KB Output is correct
67 Correct 658 ms 67692 KB Output is correct
68 Correct 655 ms 67672 KB Output is correct
69 Correct 646 ms 68264 KB Output is correct
70 Correct 671 ms 68008 KB Output is correct
71 Correct 671 ms 67904 KB Output is correct
72 Correct 684 ms 66988 KB Output is correct
73 Correct 683 ms 66728 KB Output is correct
74 Correct 690 ms 67876 KB Output is correct
75 Correct 672 ms 66472 KB Output is correct
76 Correct 669 ms 68264 KB Output is correct
77 Correct 715 ms 66824 KB Output is correct
78 Correct 682 ms 66560 KB Output is correct
79 Correct 677 ms 66984 KB Output is correct
80 Correct 664 ms 66728 KB Output is correct
81 Correct 673 ms 68044 KB Output is correct
82 Correct 680 ms 67136 KB Output is correct
83 Correct 695 ms 66756 KB Output is correct
84 Correct 676 ms 67492 KB Output is correct
85 Correct 677 ms 67496 KB Output is correct
86 Correct 680 ms 66468 KB Output is correct
87 Correct 692 ms 68520 KB Output is correct
88 Correct 684 ms 66724 KB Output is correct
89 Correct 676 ms 68184 KB Output is correct
90 Correct 684 ms 66988 KB Output is correct
91 Correct 683 ms 67208 KB Output is correct
92 Correct 674 ms 66760 KB Output is correct
93 Correct 678 ms 67160 KB Output is correct
94 Correct 691 ms 67712 KB Output is correct
95 Correct 704 ms 66720 KB Output is correct
96 Correct 664 ms 67552 KB Output is correct
97 Correct 677 ms 67124 KB Output is correct
98 Correct 685 ms 67020 KB Output is correct
99 Correct 681 ms 68016 KB Output is correct
100 Correct 439 ms 67448 KB Output is correct
101 Correct 428 ms 67748 KB Output is correct
102 Correct 425 ms 67240 KB Output is correct
103 Correct 431 ms 67264 KB Output is correct
104 Correct 432 ms 67756 KB Output is correct
105 Correct 472 ms 67428 KB Output is correct
106 Correct 444 ms 67504 KB Output is correct
107 Correct 449 ms 67476 KB Output is correct
108 Correct 464 ms 66724 KB Output is correct
109 Correct 458 ms 67240 KB Output is correct
110 Correct 560 ms 66476 KB Output is correct
111 Correct 568 ms 67276 KB Output is correct
112 Correct 587 ms 68240 KB Output is correct
113 Correct 575 ms 67572 KB Output is correct
114 Correct 590 ms 66724 KB Output is correct
115 Correct 573 ms 68196 KB Output is correct
116 Correct 577 ms 66628 KB Output is correct
117 Correct 568 ms 67756 KB Output is correct
118 Correct 581 ms 68008 KB Output is correct
119 Correct 565 ms 66448 KB Output is correct
120 Correct 0 ms 600 KB Output is correct
121 Correct 0 ms 604 KB Output is correct
122 Correct 596 ms 67592 KB Output is correct
123 Correct 588 ms 68004 KB Output is correct
124 Correct 586 ms 68000 KB Output is correct
125 Correct 594 ms 67604 KB Output is correct
126 Correct 590 ms 67504 KB Output is correct
127 Correct 594 ms 66728 KB Output is correct
128 Correct 582 ms 66980 KB Output is correct
129 Correct 602 ms 68256 KB Output is correct
130 Correct 588 ms 67864 KB Output is correct
131 Correct 588 ms 67596 KB Output is correct
132 Correct 607 ms 67600 KB Output is correct
133 Correct 589 ms 68272 KB Output is correct