結果

問題 No.2331 Maximum Quadrilateral
ユーザー t98slidert98slider
提出日時 2023-05-28 15:01:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 975 ms / 2,000 ms
コード長 3,168 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 171,240 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 11:12:14
合計ジャッジ時間 18,916 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 863 ms
4,376 KB
testcase_01 AC 519 ms
4,376 KB
testcase_02 AC 625 ms
4,376 KB
testcase_03 AC 627 ms
4,380 KB
testcase_04 AC 809 ms
4,380 KB
testcase_05 AC 855 ms
4,376 KB
testcase_06 AC 811 ms
4,376 KB
testcase_07 AC 717 ms
4,376 KB
testcase_08 AC 510 ms
4,376 KB
testcase_09 AC 471 ms
4,376 KB
testcase_10 AC 430 ms
4,376 KB
testcase_11 AC 461 ms
4,380 KB
testcase_12 AC 422 ms
4,376 KB
testcase_13 AC 456 ms
4,376 KB
testcase_14 AC 897 ms
4,376 KB
testcase_15 AC 69 ms
4,380 KB
testcase_16 AC 299 ms
4,384 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 85 ms
4,380 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 974 ms
4,376 KB
testcase_21 AC 975 ms
4,380 KB
testcase_22 AC 973 ms
4,384 KB
testcase_23 AC 974 ms
4,376 KB
testcase_24 AC 973 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> struct point{
    T x, y;
    point(): x(0), y(0){}
    point(T a, T b): x(a), y(b){}
    point& operator += (const point& rhs) {x += rhs.x, y += rhs.y; return *this;}
    point& operator -= (const point& rhs) {x -= rhs.x, y -= rhs.y; return *this;}
    point& operator *= (const T& rhs) {x *= rhs, y *= rhs; return *this;}
    point& operator /= (const T& rhs) {x /= rhs, y /= rhs; return *this;}
    point operator +() const { return *this; }
    point operator -() const { return point() - *this; }
    friend point operator + (const point& lhs, const point& rhs) {return point(lhs) += rhs;}
    friend point operator - (const point& lhs, const point& rhs) {return point(lhs) -= rhs;}
    friend point operator * (const point& lhs, const T& rhs) {return point(lhs) *= rhs;}
    friend point operator * (const T& lhs, const point& rhs) {return point(rhs) *= lhs;}
    friend point operator / (const point& lhs, const T& rhs) {return point(lhs) /= rhs;}
    friend T operator * (const point& lhs, const point& rhs) {return lhs.x * rhs.x + lhs.y * rhs.y;}
    friend T operator ^ (const point& lhs, const point& rhs) {return lhs.x * rhs.y - lhs.y * rhs.x;}
    friend bool operator == (const point& lhs, const point& rhs) {return (lhs.x == rhs.x && lhs.y == rhs.y);}
    friend istream& operator >> (istream& os, point& rhs) noexcept {
        os >> rhs.x >> rhs.y;
        return os;
    }
    friend constexpr ostream& operator << (ostream &os, const point& rhs) noexcept {
        return os << '('<< rhs.x << ',' << rhs.y << ')';
    }
    double norm(){return sqrt(x * x + y * y);}
    T norm2(){return x * x + y * y;}
    int orthant(){//第何象限かのベクトルを返す(0,0は0象限とする)
        if(x == 0 && y == 0)return 0;
        if(y > 0)return (x > 0 ? 1 : 2);
        return (x > 0 ? 4 : 3);
    }
    //偏角ソート->ベクトルの大きさの小さい順の優先度
    friend bool operator < (point &lhs, point &rhs){//tupleとかでソートできないときは&を外すと良いかもしれない
        int lo = lhs.orthant(), ro = rhs.orthant();
        if(lo != ro)return (lo < ro);
        T cv = (lhs ^ rhs);
        if(cv != 0)return (cv > 0);
        return (lhs.norm2() < rhs.norm2());
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<point<ll>> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll INF = 1ll << 61;
    ll ans = -INF;
    for(int i = 0; i < n; i++){
        vector<vector<ll>> dp(5, vector<ll>(n, -INF));
        vector<vector<ll>> dp2(5, vector<ll>(n, -INF));
        dp[0][i] = dp2[0][i] = 0;
        for(int j = 0; j < 4; j++){
            for(int k = 0; k < n; k++){
                for(int l = 0; l < n; l++){
                	if(k == l) continue;
                    dp[j + 1][l] = max(dp[j + 1][l], dp[j][k] + (a[k] ^ a[l]));
                    dp2[j + 1][l] = max(dp2[j + 1][l], dp2[j][k] - (a[k] ^ a[l]));
                }
            }
        }
        ans = max(ans, max(dp[4][i], dp2[4][i]));
    }
    cout << ans << '\n';
}
0