結果

問題 No.2331 Maximum Quadrilateral
ユーザー KKT89KKT89
提出日時 2023-05-28 14:56:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,741 bytes
コンパイル時間 2,900 ms
コンパイル使用メモリ 219,760 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 10:55:41
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

const double eps=1e-10;

struct point{
    ll x,y;
    point() {}
    point(ll x,ll y): x(x), y(y) {}
    point& operator-=(const point &p){
        x -= p.x; y -= p.y;
        return *this;
    }
    point& operator+=(const point &p){
        x += p.x; y += p.y;
        return *this;
    }
    point& operator*=(double d){
        x *= d; y *= d;
        return *this;
    }
    point& operator/=(double d){
        x /= d; y /= d;
        return *this;
    }
    const point operator+ (const point& p) const;
    const point operator- (const point& p) const;
    const point operator* (double d) const;
    const point operator/ (double d) const;
};
const point point::operator+ (const point& p) const{
    point res(*this); return res += p;
}
const point point::operator- (const point& p) const{
    point res(*this); return res -= p;
}
const point point::operator* (double d) const{
    point res(*this); return res *= d;
}
const point point::operator/ (double d) const{
    point res(*this); return res /= d;
}

struct line{
    point A,B;
    line() {}
    line(point A, point B): A(A), B(B) {}
};
// A+B
point sum(point A,point B){
    A.x+=B.x; A.y+=B.y; return A;
}
// A-B
point sub(point A,point B){
    A.x-=B.x; A.y-=B.y; return A;
}
// A to B
point vec(line L){
    return (L.B - L.A);
}

ll dot(point a,point b){
    return a.x*b.x+a.y*b.y;
}

ll cross(point a,point b){
    return a.x*b.y-a.y*b.x;
}

int ccw(point a,point b,point c){
    b={b.x-a.x,b.y-a.y};
    c={c.x-a.x,c.y-a.y};
    if(cross(b,c)>eps)return 1; // a,b,c反時計回り
    if(cross(b,c)<-eps)return -1; // a,b,c時計周り
    if(dot(b,c)<-eps)return 2; // c,a,b 一直線
    if((b.x*b.x+b.y*b.y)<(c.x*c.x+c.y*c.y))return -2; // a,b,c 一直線
    return 0; // a,c,b 一直線
}

// 凸包
// AOJ 2827
vector<point> convex_hull(vector<point> ps){
    int n = ps.size();
    int k = 0; // 凸包の頂点数
    sort(ps.begin(), ps.end(), [&](auto p, auto q){
        if(p.x < q.x - eps) return true;
        if(p.x > q.x + eps) return false;
        return p.y < q.y;
    });
    vector<point> qs(2*n); // 構築中の凸包
    for(int i=0;i<n;qs[k++]=ps[i++]){
        while(k>=2&&ccw(qs[k-2],qs[k-1],ps[i])<=0) --k;
    }
    for(int i=n-2,t=k+1;i>=0;qs[k++]=ps[i--]){
        while(k>=t&&ccw(qs[k-2],qs[k-1],ps[i])<=0) --k;
    }
    qs.resize(k-1);
    return qs;
}

// AOJ-2160
// 多角形の符号付き面積(反時計回りが正)
ll area(vector<point> g){
    ll res=0.0;
    for(int i=0;i+1<g.size();i++){
        res+=cross(g[i],g[(i+1)]);
    }
    // ここは未verify
    if(res < eps){
        res = -res;
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<point> p(n);
    for (int i = 0; i < n; ++i) {
        int x,y; cin >> x >> y;
        p[i] = point(x,y);
    }
    auto ps = convex_hull(p);
    if (ps.size() >= 4) {
        p = ps;
    }
//    p = convex_hull(p);
    ll res = 0;
    n = p.size();
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            for (int k = j+1; k < n; ++k) {
                for (int l = k+1; l < n; ++l) {
                    res = max(res, area(vector<point>{p[i],p[j],p[k],p[l],p[i]}));
                }
            }
        }
    }
    cout << res << endl;
}
0