QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810229#3139. Largest QuadrilateralSGColinAC ✓553ms4036kbC++203.1kb2024-12-11 20:29:462024-12-11 20:30:31

Judging History

This is the latest submission verdict.

  • [2024-12-11 20:30:31]
  • Judged
  • Verdict: AC
  • Time: 553ms
  • Memory: 4036kb
  • [2024-12-11 20:29:46]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int rd() {
	int x = 0;
	bool f = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) f |= (c == '-');
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return f ? -x : x;
}

#define N 5007

struct Vec { 
    ll x, y, id;
    ll norm() {return x * x + y * y;}
    ll len() {return sqrt(norm());}
    Vec operator + (const Vec &obj) {return (Vec){x + obj.x, y + obj.y};} 
    Vec operator - (const Vec &obj) {return (Vec){x - obj.x, y - obj.y};} 
    Vec operator * (const ll &t) {return (Vec){x * t, y * t};}
    ll operator * (const Vec &obj) {return x * obj.x + y * obj.y;} 
    ll cross (const Vec &obj) {return x * obj.y - y * obj.x;}
    ll dis(const Vec &obj) {return ((*this) - obj).len();}
    ll dis2(const Vec &obj) {return ((*this) - obj).norm();}
    inline bool operator < (const Vec &obj) const{
        return x == obj.x ? y < obj.y : x < obj.x;
    }
    inline bool operator != (const Vec &obj) const{
    	return x != obj.x || y != obj.y || id != obj.id;
	}
} p[N], s[N];

inline bool cmp(Vec a, Vec b) {
    ll d = (a - p[1]).cross(b - p[1]);
    return d == 0 ? a.dis2(p[1]) < b.dis2(p[1]) : d > 0;
}

inline ll labs(ll x) {
	return x > 0 ? x : -x;
}

inline ll sz(Vec a, Vec b, Vec c) {
	return labs(a.cross(b) + b.cross(c) + c.cross(a));
}

inline ll sz(Vec a, Vec b, Vec c, Vec d) {
	return labs(a.cross(b) + b.cross(c) + c.cross(d) + d.cross(a));
}

#define nxt(x) (((x) + 1) % n)

inline void work() {
    int n = rd();
    for (int i = 1; i <= n; ++i) {
    	p[i].x = rd(); p[i].y = rd(); p[i].id = i;
        if (p[i] < p[1]) swap(p[1], p[i]);
    }
    sort(p + 2, p + 1 + n, cmp);
    int top = 1;
    s[0] = p[1]; s[1] = p[2];
    for (int i = 3; i <= n; ++i) {
        for (; top && (s[top] - s[top - 1]).cross(p[i] - s[top - 1]) < 0; --top);
        s[++top] = p[i];
    }
    if (top < 2) {puts("0"); return;}
	if (top == 2) {
		ll totsz = sz(s[0], s[1], s[2]), ans = 0;
		for (int i = 1; i <= n; ++i)
			if (p[i] != s[0] && p[i] != s[1] && p[i] != s[2]) {
				ll tmp = min(min(sz(s[0], s[1], p[i]), sz(s[0], s[2], p[i])), sz(s[1], s[2], p[i]));
				ans = max(ans, totsz - tmp);
			}
		printf("%lld", ans / 2);
		puts((ans & 1) ? ".5" : ""); return;
	} 
	n = top + 1;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
    	int ptr1 = (i + 1) % n;
    	int ptr2 = (i + 3) % n;
    	for (int j = i + 2; j < n - (i == 0); ++j) {
    		if (ptr1 == i) ptr1 = nxt(ptr1);
    		if (ptr2 == j) ptr2 = nxt(ptr2);
    		for (; sz(s[i], s[j], s[nxt(ptr1)]) > sz(s[i], s[j], s[ptr1]); ) {
    			ptr1 = nxt(ptr1);
    			if (ptr1 == j) {ptr1 = (ptr1 - 1 + n) % n; break;}
			}
    		for (; sz(s[i], s[j], s[nxt(ptr2)]) > sz(s[i], s[j], s[ptr2]); ) {
    			ptr2 = nxt(ptr2); 
    			if (ptr2 == i) {ptr2 = (ptr2 - 1 + n) % n; break;}
			}			
			ans = max(ans, sz(s[i], s[j], s[ptr1]) + sz(s[i], s[j], s[ptr2]));
		}
	}
	printf("%lld", ans / 2);
	puts((ans & 1) ? ".5" : ""); 
}

int main() {
	for (int t = rd(); t; --t) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3764kb

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

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

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

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: 1ms
memory: 3924kb

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: 553ms
memory: 4036kb

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