Submission #122662

# Submission time Handle Problem Language Result Execution time Memory
122662 2019-06-29T05:09:54 Z 윤교준(#3000) Bulldozer (JOI17_bulldozer) C++14
100 / 100
1216 ms 16380 KB
#include <bits/stdc++.h>
#define upmax(a,b) (a)=max((a),(b))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
pll operator + (const pll &a, const pll &b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll &a, const pll &b) { return pll(a.first-b.first, a.second-b.second); }
ll operator * (const pll &a, const pll &b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll &a, const pll &b, const pll &c) { return a*b + b*c + c*a; }

const int MAXN = 2005;

struct SEG {
	ll ds[MAXN*4], dl[MAXN*4], dr[MAXN*4], dp[MAXN*4];

	void upd(int i, int s, int e, int x, int r) {
		if(s == e) {
			ds[i] = r;
			dl[i] = dr[i] = dp[i] = max(0, r);
			return;
		}
		int m = (s+e) >> 1;
		if(x <= m) upd(i<<1, s, m, x, r);
		else upd(i<<1|1, m+1, e, x, r);
		ds[i] = ds[i<<1] + ds[i<<1|1];
		dl[i] = max(dl[i<<1], ds[i<<1] + dl[i<<1|1]);
		dr[i] = max(dr[i<<1|1], ds[i<<1|1] + dr[i<<1]);
		dp[i] = max({dp[i<<1], dp[i<<1|1], dr[i<<1] + dl[i<<1|1]});
	}
	ll get() { return dp[1]; }
} seg;

pii EV[MAXN*MAXN/2];
pair<pll, int> P[MAXN];
int A[MAXN], B[MAXN];

ll Ans;
int N, EVn;

ll cmpccw(const pii &a, const pii &b) {
	return ccw(P[a.first].first, P[a.second].first
		, P[b.second].first - P[b.first].first + P[a.first].first);
}
bool cmp(const pii &a, const pii &b) {
	ll t = cmpccw(a, b);
	return t ? 0 < t : a < b;
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++)
		cin >> P[i].first.first >> P[i].first.second >> P[i].second;
	sort(P+1, P+N+1);

	for(int i = 1; i < N; i++) for(int j = i+1; j <= N; j++)
		EV[++EVn] = pii(i, j);
	sort(EV+1, EV+EVn+1, cmp);

	iota(B, B+N+1, 0);
	for(int i = 1; i <= N; i++) seg.upd(1, 1, N, i, A[i] = P[i].second);

	Ans = seg.get();
	for(int s = 1, e; s <= EVn; s = e) {
		for(e = s+1; e <= EVn && !cmpccw(EV[s], EV[e]); e++);
		for(int i = s, a, b; i < e; i++) {
			tie(a, b) = EV[i];
			seg.upd(1, 1, N, B[a], A[b]);
			seg.upd(1, 1, N, B[b], A[a]);
			swap(B[a], B[b]);
		}
		upmax(Ans, seg.get());
	}

	cout << Ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 380 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 380 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 380 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 1154 ms 16212 KB Output is correct
34 Correct 1118 ms 16380 KB Output is correct
35 Correct 1131 ms 16340 KB Output is correct
36 Correct 1116 ms 16344 KB Output is correct
37 Correct 1122 ms 16248 KB Output is correct
38 Correct 1110 ms 16248 KB Output is correct
39 Correct 1108 ms 16248 KB Output is correct
40 Correct 1115 ms 16120 KB Output is correct
41 Correct 1128 ms 16272 KB Output is correct
42 Correct 1108 ms 16248 KB Output is correct
43 Correct 1118 ms 16120 KB Output is correct
44 Correct 1096 ms 16120 KB Output is correct
45 Correct 1087 ms 16120 KB Output is correct
46 Correct 1121 ms 16252 KB Output is correct
47 Correct 1099 ms 16248 KB Output is correct
48 Correct 1109 ms 16252 KB Output is correct
49 Correct 1123 ms 16376 KB Output is correct
50 Correct 1098 ms 16248 KB Output is correct
51 Correct 1099 ms 16248 KB Output is correct
52 Correct 1101 ms 16248 KB Output is correct
53 Correct 1101 ms 16248 KB Output is correct
54 Correct 1108 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 4 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 380 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 1154 ms 16212 KB Output is correct
34 Correct 1118 ms 16380 KB Output is correct
35 Correct 1131 ms 16340 KB Output is correct
36 Correct 1116 ms 16344 KB Output is correct
37 Correct 1122 ms 16248 KB Output is correct
38 Correct 1110 ms 16248 KB Output is correct
39 Correct 1108 ms 16248 KB Output is correct
40 Correct 1115 ms 16120 KB Output is correct
41 Correct 1128 ms 16272 KB Output is correct
42 Correct 1108 ms 16248 KB Output is correct
43 Correct 1118 ms 16120 KB Output is correct
44 Correct 1096 ms 16120 KB Output is correct
45 Correct 1087 ms 16120 KB Output is correct
46 Correct 1121 ms 16252 KB Output is correct
47 Correct 1099 ms 16248 KB Output is correct
48 Correct 1109 ms 16252 KB Output is correct
49 Correct 1123 ms 16376 KB Output is correct
50 Correct 1098 ms 16248 KB Output is correct
51 Correct 1099 ms 16248 KB Output is correct
52 Correct 1101 ms 16248 KB Output is correct
53 Correct 1101 ms 16248 KB Output is correct
54 Correct 1108 ms 16376 KB Output is correct
55 Correct 1117 ms 16340 KB Output is correct
56 Correct 1107 ms 16376 KB Output is correct
57 Correct 1135 ms 16340 KB Output is correct
58 Correct 1123 ms 16252 KB Output is correct
59 Correct 1116 ms 16248 KB Output is correct
60 Correct 1124 ms 16376 KB Output is correct
61 Correct 1108 ms 16248 KB Output is correct
62 Correct 1130 ms 16248 KB Output is correct
63 Correct 1216 ms 16212 KB Output is correct
64 Correct 1117 ms 16248 KB Output is correct
65 Correct 1110 ms 16248 KB Output is correct
66 Correct 1118 ms 16248 KB Output is correct
67 Correct 1101 ms 16376 KB Output is correct
68 Correct 1117 ms 16376 KB Output is correct
69 Correct 1105 ms 16376 KB Output is correct
70 Correct 1139 ms 16376 KB Output is correct
71 Correct 1107 ms 16276 KB Output is correct
72 Correct 1144 ms 16376 KB Output is correct
73 Correct 1142 ms 16344 KB Output is correct
74 Correct 1133 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 380 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 4 ms 504 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 4 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 380 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 380 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 3 ms 376 KB Output is correct
47 Correct 4 ms 376 KB Output is correct
48 Correct 1154 ms 16212 KB Output is correct
49 Correct 1118 ms 16380 KB Output is correct
50 Correct 1131 ms 16340 KB Output is correct
51 Correct 1116 ms 16344 KB Output is correct
52 Correct 1122 ms 16248 KB Output is correct
53 Correct 1110 ms 16248 KB Output is correct
54 Correct 1108 ms 16248 KB Output is correct
55 Correct 1115 ms 16120 KB Output is correct
56 Correct 1128 ms 16272 KB Output is correct
57 Correct 1108 ms 16248 KB Output is correct
58 Correct 1118 ms 16120 KB Output is correct
59 Correct 1096 ms 16120 KB Output is correct
60 Correct 1087 ms 16120 KB Output is correct
61 Correct 1121 ms 16252 KB Output is correct
62 Correct 1099 ms 16248 KB Output is correct
63 Correct 1109 ms 16252 KB Output is correct
64 Correct 1123 ms 16376 KB Output is correct
65 Correct 1098 ms 16248 KB Output is correct
66 Correct 1099 ms 16248 KB Output is correct
67 Correct 1101 ms 16248 KB Output is correct
68 Correct 1101 ms 16248 KB Output is correct
69 Correct 1108 ms 16376 KB Output is correct
70 Correct 1117 ms 16340 KB Output is correct
71 Correct 1107 ms 16376 KB Output is correct
72 Correct 1135 ms 16340 KB Output is correct
73 Correct 1123 ms 16252 KB Output is correct
74 Correct 1116 ms 16248 KB Output is correct
75 Correct 1124 ms 16376 KB Output is correct
76 Correct 1108 ms 16248 KB Output is correct
77 Correct 1130 ms 16248 KB Output is correct
78 Correct 1216 ms 16212 KB Output is correct
79 Correct 1117 ms 16248 KB Output is correct
80 Correct 1110 ms 16248 KB Output is correct
81 Correct 1118 ms 16248 KB Output is correct
82 Correct 1101 ms 16376 KB Output is correct
83 Correct 1117 ms 16376 KB Output is correct
84 Correct 1105 ms 16376 KB Output is correct
85 Correct 1139 ms 16376 KB Output is correct
86 Correct 1107 ms 16276 KB Output is correct
87 Correct 1144 ms 16376 KB Output is correct
88 Correct 1142 ms 16344 KB Output is correct
89 Correct 1133 ms 16248 KB Output is correct
90 Correct 1137 ms 16348 KB Output is correct
91 Correct 1124 ms 16376 KB Output is correct
92 Correct 1125 ms 16248 KB Output is correct
93 Correct 1117 ms 16248 KB Output is correct
94 Correct 1107 ms 16248 KB Output is correct
95 Correct 1107 ms 16236 KB Output is correct
96 Correct 1117 ms 16252 KB Output is correct
97 Correct 1117 ms 16248 KB Output is correct
98 Correct 1111 ms 16376 KB Output is correct
99 Correct 1105 ms 16120 KB Output is correct
100 Correct 902 ms 16252 KB Output is correct
101 Correct 904 ms 16248 KB Output is correct
102 Correct 907 ms 16124 KB Output is correct
103 Correct 894 ms 16248 KB Output is correct
104 Correct 883 ms 16372 KB Output is correct
105 Correct 958 ms 16248 KB Output is correct
106 Correct 943 ms 16248 KB Output is correct
107 Correct 923 ms 16336 KB Output is correct
108 Correct 932 ms 16216 KB Output is correct
109 Correct 971 ms 16248 KB Output is correct
110 Correct 1010 ms 16376 KB Output is correct
111 Correct 1004 ms 16376 KB Output is correct
112 Correct 1026 ms 16252 KB Output is correct
113 Correct 999 ms 16348 KB Output is correct
114 Correct 1029 ms 16248 KB Output is correct
115 Correct 1032 ms 16376 KB Output is correct
116 Correct 1031 ms 16248 KB Output is correct
117 Correct 1026 ms 16248 KB Output is correct
118 Correct 1008 ms 16340 KB Output is correct
119 Correct 1006 ms 16248 KB Output is correct
120 Correct 2 ms 376 KB Output is correct
121 Correct 2 ms 344 KB Output is correct
122 Correct 1125 ms 16248 KB Output is correct
123 Correct 1129 ms 16340 KB Output is correct
124 Correct 1139 ms 16220 KB Output is correct
125 Correct 1122 ms 16248 KB Output is correct
126 Correct 1099 ms 16352 KB Output is correct
127 Correct 1131 ms 16272 KB Output is correct
128 Correct 1112 ms 16248 KB Output is correct
129 Correct 1110 ms 16248 KB Output is correct
130 Correct 1097 ms 16376 KB Output is correct
131 Correct 1114 ms 16376 KB Output is correct
132 Correct 1129 ms 16248 KB Output is correct
133 Correct 1096 ms 16336 KB Output is correct