結果

問題 No.2180 Comprehensive Line Segments
ユーザー 👑 kmjpkmjp
提出日時 2023-01-07 00:36:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,291 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 201,792 KB
実行使用メモリ 6,024 KB
最終ジャッジ日時 2023-08-21 05:56:35
合計ジャッジ時間 7,904 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 618 ms
5,860 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 296 ms
5,672 KB
testcase_10 AC 304 ms
5,948 KB
testcase_11 AC 290 ms
5,668 KB
testcase_12 AC 128 ms
4,576 KB
testcase_13 AC 756 ms
5,676 KB
testcase_14 AC 386 ms
5,668 KB
testcase_15 AC 323 ms
5,740 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 81 ms
4,376 KB
testcase_18 AC 756 ms
5,668 KB
testcase_19 AC 259 ms
4,512 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 84 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 27 ms
4,384 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 33 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
int X[12],Y[12];
int dp[1<<12][12][12];

int on(int a,int b,int c) {
	int dx=X[b]-X[a];
	int dy=Y[b]-Y[a];
	int ex=X[c]-X[b];
	int ey=Y[c]-Y[b];
	int g=__gcd(abs(dx),abs(dy));
	dx/=g;
	dy/=g;
	g=__gcd(abs(ex),abs(ey));
	ex/=g;
	ey/=g;
	return dx==ex&&dy==ey;
}
int sgn(int a,int b,int c,int d) {
	int dx=X[b]-X[a];
	int dy=Y[b]-Y[a];
	int ex=X[d]-X[c];
	int ey=Y[d]-Y[c];
	int z=dx*ey-dy*ex;
	if(z<0) return -1;
	if(z>0) return 1;
	return 0;
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
	}
	if(N==1) {
		cout<<1<<endl;
		return;
	}
	int mask,mask2;
	FOR(mask,1<<N) {
		FOR(x,N) FOR(y,N) dp[mask][x][y]=100;
	}
	FOR(x,N) FOR(y,N) if(x!=y) dp[(1<<x)|(1<<y)][x][y]=1;
	FOR(mask,1<<N) {
		FOR(x,N) FOR(y,N) if(x!=y&&(mask&(1<<x))&&(mask&(1<<y))) {
			FOR(i,N) if((mask&(1<<i))==0) {
				chmin(dp[mask^(1<<i)][y][i],dp[mask][x][y]+(on(x,y,i)^1));
				FOR(j,N) if((mask&(1<<j))==0&&i!=j) {
					if(on(x,y,i)&&on(y,i,j)) chmin(dp[mask^(1<<i)^(1<<j)][i][j],dp[mask][x][y]);
					if(on(x,y,i)) chmin(dp[mask^(1<<i)^(1<<j)][i][j],dp[mask][x][y]+1);
					if(on(y,i,j)) chmin(dp[mask^(1<<i)^(1<<j)][i][j],dp[mask][x][y]+1);
					if(!on(x,y,i)&&!on(y,i,j)&&sgn(x,y,y,i)==sgn(y,i,i,j)&&sgn(x,y,y,i)==sgn(x,y,i,j)) {
						chmin(dp[mask^(1<<i)^(1<<j)][i][j],dp[mask][x][y]+1);
					}
					chmin(dp[mask^(1<<i)^(1<<j)][i][j],dp[mask][x][y]+2);
				}
			}
		}
	}
	int ret=100;
	FOR(x,N) FOR(y,N) ret=min(ret,dp[(1<<N)-1][x][y]);
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0