結果

問題 No.947 ABC包囲網
ユーザー ngtkanangtkana
提出日時 2020-04-14 21:10:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 206,616 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 18:10:08
合計ジャッジ時間 4,623 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 19 ms
6,940 KB
testcase_29 AC 19 ms
6,940 KB
testcase_30 AC 19 ms
6,944 KB
testcase_31 AC 19 ms
6,940 KB
testcase_32 AC 19 ms
6,940 KB
testcase_33 AC 19 ms
6,944 KB
testcase_34 AC 19 ms
6,940 KB
testcase_35 AC 19 ms
6,944 KB
testcase_36 AC 19 ms
6,940 KB
testcase_37 AC 19 ms
6,944 KB
testcase_38 AC 19 ms
6,940 KB
testcase_39 AC 19 ms
6,944 KB
testcase_40 AC 19 ms
6,944 KB
testcase_41 AC 18 ms
6,940 KB
testcase_42 AC 18 ms
6,944 KB
testcase_43 AC 18 ms
6,940 KB
testcase_44 AC 18 ms
6,940 KB
testcase_45 AC 19 ms
6,944 KB
testcase_46 AC 18 ms
6,940 KB
testcase_47 AC 18 ms
6,940 KB
testcase_48 AC 17 ms
6,940 KB
testcase_49 AC 18 ms
6,944 KB
testcase_50 AC 18 ms
6,940 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 2 ms
6,944 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 2 ms
6,940 KB
testcase_57 AC 2 ms
6,940 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    using pt_t=std::pair<lint,lint>;
    std::vector<pt_t>pt(n);
    for(auto&&p:pt)std::cin>>p.first>>p.second;
    auto det=[&](auto&&p,auto&&q){
        lint a,b;std::tie(a,b)=p;
        lint c,d;std::tie(c,d)=q;
        return a*d-b*c;
    };
    auto inn=[&](auto&&p,auto&&q){
        lint a,b;std::tie(a,b)=p;
        lint c,d;std::tie(c,d)=q;
        return a*c+b*d;
    };
    auto colin=[&det,&inn](auto&&p,auto&&q){return det(p,q)==0&&0<inn(p,q);};
    {
        auto it=std::partition(ALL(pt),[](auto&&p){return 0<p.second||p.second==0&&0<p.first;});
        auto less=[&det](auto&&p,auto&&q){return 0<det(p,q);};
        std::sort(pt.begin(),it,less);
        std::sort(it,pt.end(),less);
    }
    pt.resize(2*n);
    for(lint i=0;i<n;i++)pt.at(i+n)=pt.at(i);
    lint ng=0;
    for(lint l=0,r=0;l<n;l++){
        for(;l==r||r<l+n&&0<=det(pt.at(l),pt.at(r))&&!(n<=r&&colin(pt.at(l),pt.at(r)));r++);
        ng+=(r-l-1)*(r-l-2)/2;
    }
    lint doubled=0;
    for(lint l=0,r=0,L=0,R=0;l<n;l=std::max(l+1,r)){
        for(r=l;r<n&&colin(pt.at(l),pt.at(r));r++);
        for(L=r;L<l+n&&(0<det(pt.at(l),pt.at(L)));L++);
        for(R=L;R<l+n&&(0<=det(pt.at(l),pt.at(R)))&&!(n<=R&&colin(pt.at(l),pt.at(r)));R++);
        lint a=r-l,b=R-L;
        doubled+=a*b*(a+b-2)/2;
    }
    doubled/=2;
    lint ans=n*(n-1)*(n-2)/6-ng+doubled;
    std::cout<<ans<<'\n';
}
0