結果

問題 No.2012 Largest Triangle
ユーザー srtubakisrtubaki
提出日時 2022-07-15 23:54:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,500 ms
コード長 6,985 bytes
コンパイル時間 3,022 ms
コンパイル使用メモリ 214,824 KB
実行使用メモリ 14,232 KB
最終ジャッジ日時 2023-09-10 06:08:55
合計ジャッジ時間 7,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 108 ms
13,176 KB
testcase_17 AC 108 ms
13,612 KB
testcase_18 AC 108 ms
12,408 KB
testcase_19 AC 109 ms
12,796 KB
testcase_20 AC 108 ms
13,084 KB
testcase_21 AC 110 ms
13,468 KB
testcase_22 AC 108 ms
12,356 KB
testcase_23 AC 110 ms
12,472 KB
testcase_24 AC 106 ms
13,624 KB
testcase_25 AC 108 ms
14,056 KB
testcase_26 AC 116 ms
13,324 KB
testcase_27 AC 114 ms
13,116 KB
testcase_28 AC 115 ms
13,016 KB
testcase_29 AC 115 ms
13,328 KB
testcase_30 AC 115 ms
13,208 KB
testcase_31 AC 109 ms
12,348 KB
testcase_32 AC 110 ms
14,232 KB
testcase_33 AC 111 ms
13,508 KB
testcase_34 AC 110 ms
12,928 KB
testcase_35 AC 109 ms
12,724 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 51 ms
8,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region template
#include <bits/stdc++.h>

using namespace std;

// clang-format off
using ll  = long long;    using vl   = vector<ll>;  using vvl   = vector<vl>;
using ld  = long double;  using vld  = vector<ld>;  using vvld  = vector<vld>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using vb = vector<bool>; using vvb = vector<vector<bool>>;
using vs = vector<string>;
using mll = map<ll, ll>;
template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>;
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = 3001001000100100100LL;
#define endl '\n'

#define  _overload(_1, _2, _3, name, ...) name
#define   rep(...) _overload(__VA_ARGS__,   _rep,   _rep2,)(__VA_ARGS__)
#define  repc(...) _overload(__VA_ARGS__,  _repc,  _repc2,)(__VA_ARGS__)
#define  repr(...) _overload(__VA_ARGS__,  _repr,  _repr2,)(__VA_ARGS__)
#define reprc(...) _overload(__VA_ARGS__, _reprc, _reprc2,)(__VA_ARGS__)
#define   _rep(i,k,n) for(ll i=(k)  , i##_xxxx=(n); i < i##_xxxx; ++i)
#define  _repc(i,k,n) for(ll i=(k)  , i##_xxxx=(n); i <=i##_xxxx; ++i)
#define  _repr(i,k,n) for(ll i=(n)-1, i##_xxxx=(k); i >=i##_xxxx; --i)
#define _reprc(i,k,n) for(ll i=(n)  , i##_xxxx=(k); i >=i##_xxxx; --i)
#define   _rep2(i,n)   _rep(i,0,n)
#define  _repc2(i,n)  _repc(i,1,n)
#define  _repr2(i,n)  _repr(i,0,n)
#define _reprc2(i,n) _reprc(i,1,n)

#define rall(o) rbegin(o), rend(o)
#define  all(o)  begin(o),  end(o)
template <class C> ll sz(const C& c) { return static_cast<ll>(c.size()); }
template <class T> bool chmax(T& m, const T& v){ if (m < v){ m = v; return true; } return false; }
template <class T> bool chmin(T& m, const T& v){ if (v < m){ m = v; return true; } return false; }
template <class T> T cdiv(const T& a, const T& b){ return (a + b - 1) / b; }
template <class T> T rdiv(const T& a, const T& b){ return (a + b / 2) / b; }
template <class T, class S>             string join(const T& v, const S& sep                  ){ stringstream ss; bool f = false; for (const auto& e : v){ if (f) ss << sep; f = true; ss << e;} return ss.str(); }
template <class T, class S, class... U> string join(const T& v, const S& sep, const U& ...args){ stringstream ss; bool f = false; for (const auto& c : v){ if (f) ss << sep; f = true; ss << join(c, args...); } return ss.str(); }
template <class T>            ostream& operator<<(ostream& os, const vector<T>&            seq){ os << '[' << join(seq, ",") << ']'; return os; } template <class T>            ostream& operator<<(ostream& os, const vector<vector<T>>&    seq){ os << '[' << join(seq, ",\n ") << ']'; return os; }
template <class T>            ostream& operator<<(ostream& os, const deque<T>&             seq){ os << '[' << join(seq, ",") << ']'; return os; }
template <class T>            ostream& operator<<(ostream& os, const set<T>&               seq){ os << '{' << join(seq, ",") << '}'; return os; }
template <class T , class TH> ostream& operator<<(ostream& os, const unordered_set<T, TH>& seq){ os << '{' << join(seq, ",") << '}'; return os; }
template <class TK, class TV> ostream& operator<<(ostream& os, const map<TK, TV>&          seq){ os << '{'; bool f = false; for (const auto& e : seq){ if (f) os << ','; f = true; os << e.first << ":" << e.second; } os << '}'; return os; }
template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>&          pa){ os << '(' << pa.first << ',' << pa.second << ')'; return os; }

#if LOCAL
#define debug(...) _debug(__VA_ARGS__, __LINE__)
#else
#define debug(...)
#endif
void print() { std::cout << '\n'; }
template <class S>             void  print(const S& a){ std::cout << a << '\n'; }
template <class S>             void _debug(const S& a){ std::cerr << "(L:" << std::setw(3) << a << ")\n"; }
template <class S, class... T> void  print(const S& a, const T&... args){ std::cout << a << ' ';  print(args...); }
template <class S, class... T> void _debug(const S& a, const T&... args){ std::cerr << a << ' '; _debug(args...); }

struct setup_main { setup_main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << fixed << setprecision(15); } } setup_main_;
// clang-format on
#pragma endregion

struct Point {
    ll x, y;
    bool operator<(const Point& b) const { return x < b.x or (x == b.x and y < b.y); }
    ll operator*(const Point& b) const { return (x * b.y - b.x * y); }
};
ostream& operator<<(ostream& os, const Point& p) {
    os << pair{p.x, p.y};
    return os;
}

Point operator+(const Point& a1, const Point& a2) {
    return Point{a1.x + a2.x, a1.y + a2.y};
}

Point operator-(const Point& a1, const Point& a2) {
    return Point{a1.x - a2.x, a1.y - a2.y};
}

/*/
凸包上の点だけ考えれば良い
底辺を決め打って、高さを3分探索
    倍加すると探索が楽
/*/

void solve(int N, vector<ll>& X, vector<ll>& Y) {
    vector<Point> P(N);
    rep(i, N) {
        if (Y[i] < 0) X[i] = -X[i], Y[i] = -Y[i];
    }

    rep(i, N) P[i] = {X[i], Y[i]};
    repr(i, N) P.push_back(Point{-X[i], -Y[i]});


    vector<Point> NP;
    {
        sort(all(P));

        vector<Point> S;
        rep(i, sz(P)) {
            Point p1 = P[i];
            while (sz(S) >= 2) {
                Point p2 = S.back();
                S.pop_back();
                Point p3 = S.back();
                if ((p2 - p1) * (p3 - p2) < 0) {
                    S.push_back(p2);
                    break;
                }
            }
            S.push_back(p1);
        }
        debug(S);
        NP = S;
    }

    {
        sort(rall(P));

        vector<Point> S;
        rep(i, sz(P)) {
            Point p1 = P[i];
            while (sz(S) >= 2) {
                Point p2 = S.back();
                S.pop_back();
                Point p3 = S.back();
                if ((p2 - p1) * (p3 - p2) < 0) {
                    S.push_back(p2);
                    break;
                }
            }
            S.push_back(p1);
        }

        rep(i, sz(S)) {
            NP.push_back(S[i]);
        }
    }
    P = NP;

    debug(P);


    debug(P);

    // rep(i, N) rep(j, N) debug(i, j, P[i] * P[j]);
    ll ans = 0;

    N = sz(P) / 2;
    rep(i, N) {
        Point p = P[i];
        ll l = i, r = i + N;
        rep(_, 100) {
            // while (r - l > 2) {
            ll ml = l + (r - l) / 3, mr = r - (r - l) / 3;
            // debug(l, ml, mr, r);

            if (abs(p * P[ml]) < abs(p * P[mr]))
                l = ml;
            else
                r = mr;
        }

        // debug(p, r, p * P[l], p * P[(r + l) / 2], p * P[r]);
        chmax(ans, abs(p * P[l]));
        chmax(ans, abs(p * P[(r + l) / 2]));
        chmax(ans, abs(p * P[r]));
    }

    print(ans);
}


int main() {
    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    rep(i, N) {
        cin >> x[i] >> y[i];
    }

    solve(N, x, y);
}
0