This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct Node {
long long s, l, r, m;
Node(long long s, long long l, long long r, long long m) : s(s), l(l), r(r), m(m) {}
Node(long long w) : Node(w, max(w, 0LL), max(w, 0LL), max(w, 0LL)) {}
Node() : Node(0) {}
};
Node op(const Node &a, const Node &b) {
return Node(
a.s + b.s,
max(a.l, a.s + b.l),
max(b.r, b.s + a.r),
max(max(a.m, b.m), a.r + b.l)
);
}
#define MAX_N (1<<11)
Node seg[MAX_N*2-1];
void update(int k, Node x) {
k += MAX_N-1;
seg[k] = x;
while (k > 0) {
k = (k-1)/2;
seg[k] = op(seg[k*2+1], seg[k*2+2]);
}
}
int N;
int X[2000], Y[2000], W[2000];
struct Rel {
int p, q;
Rel(int p, int q) : p(p), q(q) {
if (q < 0) p = -p, q = -q;
}
bool operator<(const Rel& b) const { return 1LL*p*b.q < 1LL*b.p*q; }
bool operator==(const Rel& b) const { return 1LL*p*b.q == 1LL*b.p*q; }
};
int pos[2000], rev[2000];
vector<int> G[1999000];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N;
vector<P2> ps;
rep(i, N) {
int x, y, w;
cin >> x >> y >> w;
ps.pb(P2(P(x, -y), w));
}
sort(all(ps));
rep(i, N) {
X[i] = ps[i]._1._1, Y[i] = -ps[i]._1._2, W[i] = ps[i]._2;
pos[i] = i, rev[i] = i;
update(i, Node(W[i]));
}
if (N == 1) {
cout << max(W[0], 0) << "\n";
return 0;
}
vector<pair<Rel, P>> lines;
rep(i, N) rep(j, i) {
Rel r = Rel(-1, 0);
if (X[i] != X[j]) r = Rel(Y[i]-Y[j], X[i]-X[j]);
lines.pb(make_pair(r, P(i, j)));
}
sort(all(lines));
long long m = seg[0].m;
vector<long long> bs;
Rel a = lines[0]._1;
vector<int> ln;
rep(e, lines.size()) {
if (!(a == lines[e]._1)) a = lines[e]._1;
P p = lines[e]._2;
bs.pb(1LL*Y[p._1]*a.q-1LL*X[p._1]*a.p);
ln.pb(pos[p._1]);
ln.pb(pos[p._2]);
if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
sort(all(bs)); uniq(bs);
sort(all(ln)); uniq(ln);
for (int p : ln) {
int k = index(bs, 1LL*Y[rev[p]]*a.q-1LL*X[rev[p]]*a.p);
G[k].pb(p);
}
rep(i, bs.size()) {
vector<int> &ps = G[i];
rep(i, ps.size()/2) {
int a = rev[ps[i]], b = rev[ps[(int)ps.size()-1-i]];
swap(pos[a], pos[b]);
rev[pos[a]] = a;
rev[pos[b]] = b;
update(pos[a], Node(W[a]));
update(pos[b], Node(W[b]));
}
}
rep(i, bs.size()) G[i].clear();
bs.clear();
ln.clear();
m = max(m, seg[0].m);
}
}
cout << m << "\n";
return 0;
}
Compilation message (stderr)
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:98:3: note: in expansion of macro 'rep'
rep(e, lines.size()) {
^~~
bulldozer.cpp:105:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
~~~~^~~~~~~~~~~~~~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:112:7: note: in expansion of macro 'rep'
rep(i, bs.size()) {
^~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:114:9: note: in expansion of macro 'rep'
rep(i, ps.size()/2) {
^~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:123:7: note: in expansion of macro 'rep'
rep(i, bs.size()) G[i].clear();
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |