結果
| 問題 |
No.2012 Largest Triangle
|
| コンテスト | |
| ユーザー |
259_Momone
|
| 提出日時 | 2022-07-15 23:58:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 191 ms / 2,500 ms |
| コード長 | 1,582 bytes |
| コンパイル時間 | 4,348 ms |
| コンパイル使用メモリ | 258,304 KB |
| 最終ジャッジ日時 | 2025-01-30 09:16:04 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 41 |
ソースコード
#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));
auto M{size(upper)};
for(unsigned long i{}; i < M; ++i)upper.emplace_back(upper[i]);
long ans{};
for(unsigned long i{}, j{}; i < M; ++i){
while(j + 1 < 2 * M && upper[i].first * upper[j].second + upper[i].second * upper[j + 1].first > upper[i].second * upper[j].first + upper[i].first * upper[j + 1].second)++j;
ans = max(ans, upper[i].second * upper[j].first - upper[i].first * upper[j].second);
}
cout << ans << endl;
return 0;
}
259_Momone