#include <bits/stdc++.h>
using namespace std;
using pii = pair <int, int>;
const int maxn = 2005;
struct point {
long long x, y, w;
point () {}
point (long long x, long long y) : x(x), y(y) {}
point operator - (point p) {
return point(x - p.x, y - p.y);
}
point operator + (point p) {
return point(x + p.x, y + p.y);
}
point normalize() {
long long d = __gcd(abs(x), abs(y));
if(d == 0) return *this;
else return point(x / d, y / d);
}
} a[maxn];
long long dot(point p, point q) { return p.x*q.x + p.y*q.y; }
long long cross(point p, point q) { return p.x*q.y - q.x*p.y; }
bool operator < (point p, point q) {
return cross(p, q) > 0;
}
long long dist(point p) { return dot(p, p); }
bool vis[maxn];
int n;
int cost[maxn];
int pos[maxn], c[maxn];
struct data {
long long sum, opt, pre, suf;
} t[maxn * 4];
data merge(data p, data q) {
data x;
x.sum = p.sum + q.sum;
x.pre = max(p.pre, p.sum + q.pre);
x.suf = max(q.suf, q.sum + p.suf);
x.opt = max(p.opt, q.opt);
x.opt = max(x.opt, p.suf + q.pre);
return x;
}
void update(int x, int val, int c = 1, int b = 1, int e = n) {
if(b == e) {
t[c].sum = val;
t[c].pre = t[c].suf = t[c].opt = max(0, val);
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(x <= m) update(x, val, l, b, m);
else update(x, val, r, m + 1, e);
t[c] = merge(t[l], t[r]);
}
long long maxSubarray() {
return t[1].opt;
}
int main() {
ios_base :: sync_with_stdio (false);
cin.tie(0);
cin >> n;
long long ans = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].w;
ans = max(ans, a[i].w);
}
sort(a + 1, a + n + 1, [&] (point p, point q) {
return make_pair(p.y, p.x) < make_pair(q.y, q.x); });
map <point, vector <pair <int, int>>> can;
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n; j++) {
point p = a[j] - a[i];
p = p.normalize();
can[p].emplace_back(i, j);
}
}
for(int i = 1; i <= n; i++) {
pos[i] = i;
c[i] = i;
cost[i] = a[i].w;
update(i, cost[i]);
}
for(auto i : can) {
vector <pair <int, int>> v = i.second;
sort(v.begin(), v.end(), [&] (pii p, pii q) {
return pos[p.second] - pos[p.first] > pos[q.second] - pos[q.first]; });
vector <pii> affected;
for(auto j : v) {
if(vis[pos[j.first]]) continue;
for(int k = pos[j.first]; k <= pos[j.second]; k++) {
vis[k] = true;
}
affected.emplace_back(pos[j.first], pos[j.second]);
}
ans = max(ans, maxSubarray());
for(auto j : affected) {
reverse(c + j.first, c + j.second + 1);
for(int k = j.first; k <= j.second; k++) {
vis[k] = false;
pos[c[k]] = k;
cost[k] = a[c[k]].w;
update(k, cost[k]);
}
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
9 ms |
1024 KB |
Output is correct |
4 |
Correct |
9 ms |
1024 KB |
Output is correct |
5 |
Correct |
12 ms |
1024 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
9 ms |
1024 KB |
Output is correct |
8 |
Correct |
9 ms |
1024 KB |
Output is correct |
9 |
Correct |
9 ms |
1024 KB |
Output is correct |
10 |
Correct |
9 ms |
1024 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
9 ms |
1024 KB |
Output is correct |
23 |
Correct |
9 ms |
1024 KB |
Output is correct |
24 |
Correct |
9 ms |
1024 KB |
Output is correct |
25 |
Correct |
9 ms |
1152 KB |
Output is correct |
26 |
Correct |
9 ms |
1024 KB |
Output is correct |
27 |
Correct |
8 ms |
1024 KB |
Output is correct |
28 |
Correct |
9 ms |
1024 KB |
Output is correct |
29 |
Correct |
8 ms |
1024 KB |
Output is correct |
30 |
Correct |
9 ms |
1024 KB |
Output is correct |
31 |
Correct |
9 ms |
1024 KB |
Output is correct |
32 |
Correct |
9 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
9 ms |
1024 KB |
Output is correct |
4 |
Correct |
9 ms |
1024 KB |
Output is correct |
5 |
Correct |
12 ms |
1024 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
9 ms |
1024 KB |
Output is correct |
8 |
Correct |
9 ms |
1024 KB |
Output is correct |
9 |
Correct |
9 ms |
1024 KB |
Output is correct |
10 |
Correct |
9 ms |
1024 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
9 ms |
1024 KB |
Output is correct |
23 |
Correct |
9 ms |
1024 KB |
Output is correct |
24 |
Correct |
9 ms |
1024 KB |
Output is correct |
25 |
Correct |
9 ms |
1152 KB |
Output is correct |
26 |
Correct |
9 ms |
1024 KB |
Output is correct |
27 |
Correct |
8 ms |
1024 KB |
Output is correct |
28 |
Correct |
9 ms |
1024 KB |
Output is correct |
29 |
Correct |
8 ms |
1024 KB |
Output is correct |
30 |
Correct |
9 ms |
1024 KB |
Output is correct |
31 |
Correct |
9 ms |
1024 KB |
Output is correct |
32 |
Correct |
9 ms |
1024 KB |
Output is correct |
33 |
Execution timed out |
2103 ms |
202092 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
9 ms |
1024 KB |
Output is correct |
4 |
Correct |
9 ms |
1024 KB |
Output is correct |
5 |
Correct |
12 ms |
1024 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
9 ms |
1024 KB |
Output is correct |
8 |
Correct |
9 ms |
1024 KB |
Output is correct |
9 |
Correct |
9 ms |
1024 KB |
Output is correct |
10 |
Correct |
9 ms |
1024 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
9 ms |
1024 KB |
Output is correct |
23 |
Correct |
9 ms |
1024 KB |
Output is correct |
24 |
Correct |
9 ms |
1024 KB |
Output is correct |
25 |
Correct |
9 ms |
1152 KB |
Output is correct |
26 |
Correct |
9 ms |
1024 KB |
Output is correct |
27 |
Correct |
8 ms |
1024 KB |
Output is correct |
28 |
Correct |
9 ms |
1024 KB |
Output is correct |
29 |
Correct |
8 ms |
1024 KB |
Output is correct |
30 |
Correct |
9 ms |
1024 KB |
Output is correct |
31 |
Correct |
9 ms |
1024 KB |
Output is correct |
32 |
Correct |
9 ms |
1024 KB |
Output is correct |
33 |
Execution timed out |
2103 ms |
202092 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
1024 KB |
Output is correct |
17 |
Correct |
9 ms |
1024 KB |
Output is correct |
18 |
Correct |
9 ms |
1024 KB |
Output is correct |
19 |
Correct |
9 ms |
1024 KB |
Output is correct |
20 |
Correct |
12 ms |
1024 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
9 ms |
1024 KB |
Output is correct |
23 |
Correct |
9 ms |
1024 KB |
Output is correct |
24 |
Correct |
9 ms |
1024 KB |
Output is correct |
25 |
Correct |
9 ms |
1024 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
6 ms |
384 KB |
Output is correct |
36 |
Correct |
9 ms |
1024 KB |
Output is correct |
37 |
Correct |
9 ms |
1024 KB |
Output is correct |
38 |
Correct |
9 ms |
1024 KB |
Output is correct |
39 |
Correct |
9 ms |
1024 KB |
Output is correct |
40 |
Correct |
9 ms |
1152 KB |
Output is correct |
41 |
Correct |
9 ms |
1024 KB |
Output is correct |
42 |
Correct |
8 ms |
1024 KB |
Output is correct |
43 |
Correct |
9 ms |
1024 KB |
Output is correct |
44 |
Correct |
8 ms |
1024 KB |
Output is correct |
45 |
Correct |
9 ms |
1024 KB |
Output is correct |
46 |
Correct |
9 ms |
1024 KB |
Output is correct |
47 |
Correct |
9 ms |
1024 KB |
Output is correct |
48 |
Execution timed out |
2103 ms |
202092 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |