結果

問題 No.2012 Largest Triangle
ユーザー 259_Momone
提出日時 2022-07-15 23:06:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,260 bytes
コンパイル時間 2,664 ms
コンパイル使用メモリ 257,824 KB
最終ジャッジ日時 2025-01-30 08:50:39
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> points(N);
    for(auto&& [x, y] : points)cin >> x >> y;
    sort(begin(points), end(points));
    const auto cross_product{[](auto&& i, auto&& j, auto&& k){
        auto&& [x0, y0]{i};
        auto&& [x1, y1]{j};
        auto&& [x2, y2]{k};
        const auto a{x0 * y1 + x1 * y2 + x2 * y0}, b{x0 * y2 + x1 * y0 + x2 * y1};
        return (a < b) - (a > b);
    }};
    vector<pair<long, long>> upper, lower;
    for(const auto& now : points){
        while(size(upper) > 1 && cross_product(upper.end()[-2], upper.end()[-1], now) < 0)upper.pop_back();
        upper.emplace_back(now);
    }
    for(const auto& now : points){
        while(size(lower) > 1 && cross_product(lower.end()[-2], lower.end()[-1], now) > 0)lower.pop_back();
        lower.emplace_back(now);
    }
    reverse(begin(lower), end(lower));
    if(upper.front() == lower.back())lower.pop_back();
    if(lower.front() == upper.back())upper.pop_back();
    upper.insert(end(upper), begin(lower), end(lower));
    long ans{};
    for(const auto& [x, y] : upper)for(const auto& [z, w] : upper)ans = max(ans, x * w - y * z);
    cout << ans << endl;
    return 0;
}
0