結果
| 問題 |
No.947 ABC包囲網
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-14 20:02:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,672 bytes |
| コンパイル時間 | 2,966 ms |
| コンパイル使用メモリ | 203,428 KB |
| 最終ジャッジ日時 | 2025-01-09 18:53:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 WA * 12 |
ソースコード
#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*b+c*d;
};
auto less=[&det](auto&&p,auto&&q){return 0<det(p,q);};
auto leq=[&det](auto&&p,auto&&q){return 0<=det(p,q);};
auto colin=[&det,&inn](auto&&p,auto&&q){return det(p,q)==0&&0<inn(p,q);};
lint ppt=-1;
{
auto it=std::partition(ALL(pt),[](auto&&p){return 0<p.second||p.second==0&&0<p.first;});
ppt=it-pt.begin();
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 ans=0;
for(lint l=0,r=0;l<n;l++){
for(;l==r||r<l+n&&leq(pt.at(l),pt.at(r));r++);
ans+=(r-l-1)*(r-l-2)/2;
}
for(lint l=0,r=0,L=0,R=0;l<ppt;l=std::max(l+1,r)){
for(r=l;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)));R++);
lint a=r-l,b=R-L;
ans-=a*b*(a+b-2)/2;
}
ans=n*(n-1)*(n-2)/6-ans;
std::cout<<ans<<'\n';
}
ngtkana