結果
| 問題 |
No.2180 Comprehensive Line Segments
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2022-12-16 02:26:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,021 bytes |
| コンパイル時間 | 2,307 ms |
| コンパイル使用メモリ | 209,936 KB |
| 最終ジャッジ日時 | 2025-02-09 14:14:15 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 2 |
ソースコード
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}
void solve();
// oddloop
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
//cin>>t;
rep(i,0,t) solve();
}
void solve(){
int N;
cin>>N;
vector<pair<int,int>> p(N);
rep(i,0,N){
cin>>p[i].first>>p[i].second;
}
So(p);
if(N<=2){
cout<<"1\n";
return;
}
auto f=[&](pair<int,int> &a,pair<int,int> &b,pair<int,int> &c)->int{
int A=b.second-a.second;
int B=a.first-b.first;
int C=a.second*b.first-b.second*a.first;
return A*c.first+B*c.second+C;
};
auto g=[&](int a,int b)->int{
return a*N+b;
};
vector<vector<int>> dp((1<<N),vector<int>(N*N,N+1));
rep(i,0,N) rep(j,0,N){
if(i==j) continue;
dp[(1<<i)+(1<<j)][g(i,j)]=1;
}
rep(i,0,(1<<N)){
vector<int> A;
vector<int> B;
rep(j,0,N){
if(i&(1<<j)) A.push_back(j);
else B.push_back(j);
}
if((int)A.size()<=1) continue;
for(auto a:A) for(auto b:A){
if(dp[i][g(a,b)]==N+1) continue;
int tmp=dp[i][g(a,b)];
for(auto c:B){
chmin(dp[i+(1<<c)][g(b,c)],tmp+1);
if((p[a].first-p[b].first)*(p[b].second-p[c].second)==(p[a].second-p[b].second)*(p[b].first-p[c].first)
&& !((p[a].first*300+p[a].second<p[b].first*300+p[b].second)^(p[b].first*300+p[b].second<p[c].first*300+p[c].second))){
chmin(dp[i+(1<<c)][g(b,c)],tmp);
}
for(auto d:B){
if(d==c) continue;
int X=f(p[b],p[c],p[d]);
int Y=f(p[b],p[c],p[a]);
if(X==0) continue;
if((X<0)^(Y<0)) continue;
X=f(p[a],p[b],p[c]);
Y=f(p[a],p[b],p[d]);
if(X<0) X*=-1,Y*=-1;
if(X<Y) chmin(dp[i+(1<<d)+(1<<c)][g(c,d)],tmp+1);
}
}
}
}
cout<<min(dp[(1<<N)-1])<<"\n";
}
potato167