QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744703 | #3139. Largest Quadrilateral | ucup-team5226 | AC ✓ | 1196ms | 4076kb | C++20 | 3.2kb | 2024-11-13 22:55:44 | 2024-11-13 22:55:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
const ll INF = LLONG_MAX / 4;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vector<T>>;
template <class T>
struct Point {
using P = Point;
T x, y;
explicit Point(T x = 0, T y = 0) : x(x), y(y) {}
bool operator<(P p) const { return tie(x, y) < tie(p.x, p.y); }
bool operator==(P p) const { return tie(x, y) == tie(p.x, p.y); }
P operator-(P p) const { return P(x - p.x, y - p.y); }
T cross(P p) const { return x * p.y - y * p.x; }
T cross(P a, P b) const { return (a - *this).cross(b - *this); }
};
using P = Point<ll>;
vc<P> ch(vc<P> pts) {
if (pts.size() <= 1) return pts;
sort(pts.begin(), pts.end());
vc<P> h(pts.size() + 1);
ll s = 0, t = 0;
for (int it = 0; it < 2; ++it, s = --t, reverse(pts.begin(), pts.end())) {
for (P p : pts) {
while (t >= s + 2 and h[t - 2].cross(h[t - 1], p) <= 0) t--;
h[t++] = p;
}
}
return {h.begin(), h.begin() + t - (t == 2 && h[0] == h[1])};
}
void solve() {
ll n;
cin >> n;
vc<P> pos;
map<P, ll> cnt;
rep(i, n) {
ll x, y;
cin >> x >> y;
pos.push_back(P(x, y));
cnt[P(x, y)]++;
}
auto v = ch(pos);
ll sz = v.size();
if (sz <= 2) {
cout << 0 << endl;
return;
}
ll res = 0;
auto calc = [&](P p1, P p2, P p3) {
p2 = p2 - p1, p3 = p3 - p1;
return abs(p2.x * p3.y - p2.y * p3.x);
};
if (sz == 3) {
ll base = calc(v[0], v[1], v[2]);
ll res = 0;
rep(i, n) {
if (pos[i] == v[0] or pos[i] == v[1] or pos[i] == v[2]) {
if (cnt[pos[i]] == 1) continue;
res = base;
} else {
rep(j, 3) {
ll area = base - calc(v[j], v[(j + 1) % 3], pos[i]);
res = max(res, area);
}
}
}
if (res % 2)
cout << res / 2 << ".5" << endl;
else
cout << res / 2 << endl;
return;
}
rep(a, sz) {
ll b = a, d = a;
for (ll c = a + 2; c < a + sz - 1; c++) {
while (b <= a) b++;
while (d <= c) d++;
while (b + 1 < c and calc(v[a], v[c % sz], v[(b + 1) % sz]) > calc(v[a], v[c % sz], v[b % sz])) b++;
while (d + 1 < a + sz - 1 and calc(v[a], v[c % sz], v[(d + 1) % sz]) > calc(v[a], v[c % sz], v[d % sz]))
d++;
res = max(res, calc(v[a], v[c % sz], v[b % sz]) + calc(v[a], v[c % sz], v[d % sz]));
}
}
if (res % 2)
cout << res / 2 << ".5" << endl;
else
cout << res / 2 << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(20);
ll t = 1;
cin >> t;
for (int i = 1; i <= t; i++) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
3 5 0 0 1 0 3 1 1 2 0 1 4 0 0 4 0 0 4 1 1 4 0 0 1 1 2 2 1 1
output:
3 6 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 4 0 0 1 0 0 1 3 2
output:
2.5
result:
ok single line: '2.5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3 4 0 0 0 0 0 0 0 0 5 0 0 1 0 3 1 1 2 0 1 4 0 0 4 0 0 4 1 1
output:
0 3 6
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
3 4 0 0 1 1 2 2 1 1 5 0 0 3 3 1 1 4 4 2 2 6 0 0 0 4 4 0 0 0 1 1 1 2
output:
0 0 8
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
3 6 0 0 8 8 7 9 6 9 5 8 0 99 29 999891293 708205 369022896 771 993004062 999827531 929592437 29458 994968624 999539287 569046020 1943 2200 986643253 11189 5792636 712825 999917190 2482686 272282 43058 665660 10373878 31825 508452623 112 3304 269412577 43817590 3789 999996618 957802194 999902626 9749...
output:
388 996775018731291724.5 965005706567704502.5
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 1196ms
memory: 3984kb
input:
3 4096 53819837 441491349 842988334 208694314 834815184 199336081 754579314 871065186 798603871 163346278 881287987 261003199 69176974 629967383 167500703 196776949 934427498 382642646 949669136 517253054 205028216 839840619 904403509 697377307 909983630 685508552 106436006 718191161 704172704 90101...
output:
405000001187842381 405000001187842381 405000001187842381
result:
ok 3 lines