QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744700#3139. Largest Quadrilateralucup-team5226TL 2ms4324kbC++204.1kb2024-11-13 22:54:502024-11-13 22:54:54

Judging History

This is the latest submission verdict.

  • [2024-11-13 22:54:54]
  • Judged
  • Verdict: TL
  • Time: 2ms
  • Memory: 4324kb
  • [2024-11-13 22:54:50]
  • Submitted

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]));
        }
    }
    rep(i, sz) rep(j, i + 2, sz) {
        if (i == 0 and j == sz - 1) break;
        ll l = i + 1, r = j - 1;
        while (r - l > 2) {
            ll l1 = (l * 2 + r) / 3, r1 = (l + r * 2) / 3;
            if (calc(v[i], v[j], v[l1]) >= calc(v[i], v[j], v[r1]))
                r = r1;
            else
                l = l1;
        }
        ll ma = 0;
        for (ll k = l; k <= r; k++) ma = max(ma, calc(v[i], v[j], v[k]));
        l = j + 1, r = i - 1 + sz;
        while (r - l > 2) {
            ll l1 = (l * 2 + r) / 3, r1 = (l + r * 2) / 3;
            if (calc(v[i], v[j], v[l1 % sz]) >= calc(v[i], v[j], v[r1 % sz]))
                r = r1;
            else
                l = l1;
        }
        ll ma1 = 0;
        for (ll k = l; k <= r; k++) ma1 = max(ma1, calc(v[i], v[j], v[k % sz]));
        ma += ma1;
        res = max(res, ma);
    }
    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();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3504kb

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: 3560kb

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: 3520kb

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: 3612kb

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: 2ms
memory: 4324kb

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: -100
Time Limit Exceeded

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

result: