QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#535744#3139. Largest QuadrilateralThirvinWA 2ms3844kbC++172.8kb2024-08-28 14:10:572024-08-28 14:10:57

Judging History

This is the latest submission verdict.

  • [2024-08-28 14:10:57]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3844kb
  • [2024-08-28 14:10:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ld = long long;
using pii = pair<int, int> ;
using ll = long long;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define F first
#define S second
template<typename T>
pair<T, T> operator-(pair<T, T> a, pair<T, T> b){
    return mp(a.F - b.F, a.S - b.S);
}

template<typename T>
T cross(pair<T, T> a, pair<T, T> b){
    return a.F * b.S - a.S * b.F;
}

template<typename T>
vector<pair<T, T>> getConvexHull(vector<pair<T, T>>& pnts){

    sort(pnts.begin(), pnts.end());

    vector<pair<T, T>> hull;

    for(int i = 0; i < 2; i++){
        int t = hull.size();
        for(pair<T, T> pnt : pnts){
            while(hull.size() - t >= 2 && cross(hull.back() - hull[hull.size() - 2], pnt - hull[hull.size() - 2]) <= 0)
                hull.pop_back();
            hull.pb(pnt);
        }
        hull.pop_back();
        reverse(pnts.begin(), pnts.end());
    }

    return hull;
}

ld dis(pii x, pii s, pii e){
    pii v1 = pii(x.F - s.F, x.S - s.S);
    pii v2 = pii(e.F - s.F, e.S - s.S);

    ld c1 = abs(v1.F * v2.S - v1.S * v2.F);

//    ld c2 = v2.F * v2.F + v2.S * v2.S;

    return c1 ;
}

void solve(){
    int n;
    cin >> n;
    vector<pii> pnts(n);
    
    map<pii, int> cnt;
    for(auto &it : pnts){
        cin >> it.F >> it.S;
        cnt[it] += 1;
    }
    vector<pii> hull = getConvexHull(pnts);
    n = hull.size();
    ld ans = 0;
    if(n == 3){
        ans = dis(hull[0], hull[1], hull[2]);
        ld mi = 1e9;
        for(auto it : pnts){
            if((it == hull[0] && cnt[it] == 1) || (it == hull[1] && cnt[it] == 1) || (it == hull[2] && cnt[it] == 1))
                continue;
            for(int i = 0;i < 3;i ++){
                for(int j = i+1;j < 3;j ++){
                    mi = min(mi, dis(it, hull[i], hull[j]));
                }
            }

        }
        ans -= mi;
        if(ans % 2){
            cout << ans/2 << ".5\n";
        } else {
            cout << ans/2 << "\n";
        }
        return ;
    }
    for(int i = 0;i < n;i ++){
        int l1 = i+1;
        int l2 = i+3;
        for(int j = i + 2;j < n;j ++){
            while(l1 < j && dis(hull[l1], hull[i], hull[j]) < dis(hull[l1+1], hull[i], hull[j]))
                l1 += 1;
            while(l2 != i-1 && dis(hull[l2], hull[i], hull[j]) < dis(hull[l2+1], hull[i], hull[j]))
                l2 += 1;
            ans = max(dis(hull[l1], hull[i], hull[j]) + dis(hull[l2], hull[i], hull[j]), ans);
        }
    }
    if(ans % 2){
        cout << ans/2 << ".5" << "\n";
    } else {
        cout << ans/2 << "\n";
    }
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
	cin >> t;
	while(t --){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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: -100
Wrong Answer
time: 2ms
memory: 3844kb

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
2118359619
2143093853

result:

wrong answer 2nd lines differ - expected: '996775018731291724.5', found: '2118359619'