結果
| 問題 | No.3154 convex polygon judge | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-05-20 22:22:33 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 73 ms / 2,000 ms | 
| コード長 | 1,229 bytes | 
| コンパイル時間 | 2,153 ms | 
| コンパイル使用メモリ | 204,012 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-05-20 22:22:37 | 
| 合計ジャッジ時間 | 3,782 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 44 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int,int>> Totsuho(vector<pair<int,int>> &pos){
    int n=pos.size(),n1,n2;
    sort(pos.begin(),pos.end());
    vector<pair<int,int>> res1={pos[0],pos[1]},res2={pos[0],pos[1]};
    auto cross=[&](pair<int,int> a,pair<int,int> b){
        return (long long)a.first*b.second-(long long)a.second*b.first;
    };
    auto sub=[&](pair<int,int> a,pair<int,int> b){
        return make_pair(a.first-b.first,a.second-b.second);
    };
    for(int i=2;i<n;i++){
        n1=res1.size(),n2=res2.size();
        while(n1>=2&&cross(sub(res1[n1-1],res1[n1-2]),sub(pos[i],res1[n1-1]))<=0){
            res1.pop_back();
            n1--;
        }
        while(n2>=2&&cross(sub(res2[n2-1],res2[n2-2]),sub(pos[i],res2[n2-1]))>=0){
            res2.pop_back();
            n2--;
        }
        res1.push_back(pos[i]);
        res2.push_back(pos[i]);
    }
    for (int i=res2.size()-2;i>=1;i--)res1.push_back(res2[i]);
    return res1;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(auto &&[x, y] : a) cin >> x >> y;
    cout << (Totsuho(a).size() == n ? "Yes" : "No") << '\n';
}
            
            
            
        