結果
問題 | No.947 ABC包囲網 |
ユーザー |
![]() |
提出日時 | 2020-04-14 21:10:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,699 bytes |
コンパイル時間 | 2,442 ms |
コンパイル使用メモリ | 203,440 KB |
最終ジャッジ日時 | 2025-01-09 18:57:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 60 |
ソースコード
#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'; }