結果

問題 No.2180 Comprehensive Line Segments
ユーザー 👑 kmjpkmjp
提出日時 2023-01-06 23:47:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,342 bytes
コンパイル時間 2,402 ms
コンパイル使用メモリ 204,948 KB
実行使用メモリ 69,100 KB
最終ジャッジ日時 2024-05-07 23:47:46
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 68 ms
68,864 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 175 ms
69,040 KB
testcase_10 AC 148 ms
68,912 KB
testcase_11 WA -
testcase_12 AC 24 ms
31,556 KB
testcase_13 AC 66 ms
68,864 KB
testcase_14 AC 77 ms
68,916 KB
testcase_15 WA -
testcase_16 AC 5 ms
11,636 KB
testcase_17 AC 10 ms
18,836 KB
testcase_18 AC 66 ms
68,932 KB
testcase_19 AC 24 ms
32,092 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 10 ms
11,520 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 4 ms
5,504 KB
testcase_26 AC 75 ms
68,864 KB
testcase_27 AC 10 ms
20,372 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
pair<int,int> G[1<<12];
int mi[1<<12][1<<12];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
	}
	
	int mask,mask2;
	FOR(mask,1<<N) if(__builtin_popcount(mask)>=2) {
		int sx=-1000,sy=0,dx=0,dy=0;
		FOR(i,N) if(mask&(1<<i)) {
			if(sx==-1000) {
				sx=X[i];
				sy=Y[i];
			}
			else if(dx==0&&dy==0) {
				dx=X[i]-sx;
				dy=Y[i]-sy;
				int g=__gcd(abs(dx),abs(dy));
				dx/=g;
				dy/=g;
				if(dx<0) dx=-dx, dy=-dy;
				if(dx==0) dy=abs(dy);
			}
			else {
				int ex=X[i]-sx;
				int ey=Y[i]-sy;
				int g=__gcd(abs(ex),abs(ey));
				ex/=g;
				ey/=g;
				if(ex<0) ex=-ex, ey=-ey;
				if(ex==0) ey=abs(ey);
				if(ex!=dx||dy!=ey) break;
			}
		}
		if(i==N) {
			G[mask]={dx,dy};
		}
	}
	FOR(mask,1<<N) {
		FOR(mask2,1<<N) mi[mask][mask2]=10000;
		if(__builtin_popcount(mask)==1) mi[mask][mask]=1;
		if(__builtin_popcount(mask)>=2&&(G[mask].first!=0||G[mask].second!=0)) mi[mask][mask]=1;
	}
	FOR(mask,1<<N) {
		for(int mask2=mask;mask2>0;mask2=(mask2-1)&mask) if(mi[mask][mask2]<100) {
			for(int sm=(1<<N)-1-mask;sm>0;sm=(sm-1)&((1<<N)-1-mask)) {
				if(__builtin_popcount(sm)>1&&G[sm].first==0&&G[sm].second==0) continue;
				if(__builtin_popcount(mask2)==1||__builtin_popcount(sm)==1) {
					chmin(mi[mask|sm][sm],mi[mask][mask2]+1);
				}
				if(G[sm]==G[mask2]) chmin(mi[mask|sm][sm],mi[mask][mask2]+2);
				if(G[sm]!=G[mask2]) chmin(mi[mask|sm][sm],mi[mask][mask2]+1);
			}
		}
	}
	int ret=100;
	FOR(mask,1<<N) ret=min(ret,mi[(1<<N)-1][mask]);
	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