結果

問題 No.2180 Comprehensive Line Segments
ユーザー heno239heno239
提出日時 2023-01-06 23:23:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 11,299 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 177,196 KB
実行使用メモリ 36,096 KB
最終ジャッジ日時 2024-05-08 11:29:15
合計ジャッジ時間 9,383 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,972 KB
testcase_01 AC 9 ms
11,848 KB
testcase_02 AC 9 ms
11,648 KB
testcase_03 AC 977 ms
34,124 KB
testcase_04 AC 9 ms
11,904 KB
testcase_05 AC 8 ms
11,976 KB
testcase_06 AC 9 ms
11,904 KB
testcase_07 AC 8 ms
11,776 KB
testcase_08 AC 9 ms
11,852 KB
testcase_09 AC 10 ms
12,104 KB
testcase_10 AC 10 ms
12,104 KB
testcase_11 AC 130 ms
18,508 KB
testcase_12 AC 363 ms
18,816 KB
testcase_13 AC 1,302 ms
36,096 KB
testcase_14 AC 147 ms
19,272 KB
testcase_15 AC 200 ms
20,040 KB
testcase_16 AC 69 ms
12,544 KB
testcase_17 AC 196 ms
14,412 KB
testcase_18 AC 1,152 ms
34,636 KB
testcase_19 AC 527 ms
19,916 KB
testcase_20 AC 9 ms
11,776 KB
testcase_21 AC 195 ms
14,408 KB
testcase_22 AC 9 ms
11,848 KB
testcase_23 AC 27 ms
12,232 KB
testcase_24 AC 13 ms
11,852 KB
testcase_25 AC 73 ms
12,416 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 22 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}
template<typename T>
void cinarray(vector<T>& v) {
	rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
	rep(i, v.size()) {
		if (i > 0)cout << " "; cout << v[i];
	}
	cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	//if (x == 0)return 0;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
//mod should be <2^31
struct modint {
	int n;
	modint() :n(0) { ; }
	modint(ll m) {
		if (m < 0 || mod <= m) {
			m %= mod; if (m < 0)m += mod;
		}
		n = m;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
	a = abs(a); b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
using ld = long double;
//typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void addv(vector<T>& v, int loc, T val) {
	if (loc >= v.size())v.resize(loc + 1, 0);
	v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
	fill(isp + 2, isp + mn, true);
	for (int i = 2; i < mn; i++) {
		if (!isp[i])continue;
		ps.push_back(i);
		for (int j = 2 * i; j < mn; j += i) {
			isp[j] = false;
		}
	}
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	if (res == st.begin())return st.end();
	res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
	return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
	a = a + b; return a;
}
mP operator-(mP a, mP b) {
	return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
	a = a - b; return a;
}
LP operator+(LP a, LP b) {
	return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
	a = a + b; return a;
}
LP operator-(LP a, LP b) {
	return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
	a = a - b; return a;
}

mt19937 mt(time(0));

const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
//-----------------------------------------



typedef complex<ld> Point;
ld dot(Point a, Point b) { return real(conj(a) * b); }
ld cross(Point a, Point b) { return imag(conj(a) * b); }
namespace std {
	bool operator<(const Point& lhs, const Point& rhs) {
		return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
	}
}
struct Line {
	Point a, b;
};
struct Circle {
	Point p; ld r;
};
int ccw(Point a, Point b, Point c) {
	b -= a; c -= a;
	if (cross(b, c) > eps)return 1;//counter clockwise
	if (cross(b, c) < -eps)return -1;//clock wise
	if (dot(b, c) < 0)return 2;//c--a--b on line
	if (norm(b) < norm(c))return -2;//a--b--c on line
	return 0; //a--c--b on line
}
bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}
//2直線の交差判定
bool isis_ll(Line l, Line m) {
	return !eq(cross(l.b - l.a, m.b - m.a), 0);
}
//直線と線分の交差判定
bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}
//点が直線上に存在するか
bool isis_lp(Line l, Point p) {
	return (abs(cross(l.b - p, l.a - p)) < eps);
}
//点が線分上に存在するか
bool isis_sp(Line s, Point p) {
	//誤差がisis_lpに比べて大きいので、できるだけisis_lpを使う
	return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
//線分と線分の交差判定
//bool isis_ss(Line s, Line t) {
//	return(cross(s.b - s.a, t.a - s.a)*cross(s.b - s.a, t.b - s.a) < -eps && cross(t.b - t.a, s.a - t.a)*cross(t.b - t.a, s.b - t.a) < -eps);
//}
//線分と線分の交差判定2
//本当にそれは線分ですか?(check {(0,0),(2,0)},{(1,0),(1,0)})
bool isis_ss(Line s, Line t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
//点から直線への垂線の足
Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}
//直線と直線の交点
//平行な2直線に対しては使うな!!!!
Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a; Point tv = t.b - t.a;
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
//直線と点の距離
ld dist_lp(Line l, Point p) {
	return abs(p - proj(l, p));
}
//直線と直線の距離
ld dist_ll(Line l, Line m) {
	return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}
//線分と直線の距離
ld dist_ls(Line l, Line s) {
	return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}
//線分と点の距離
ld dist_sp(Line s, Point p) {
	Point r = proj(s, p);
	return isis_sp(s, r) ? abs(p - r) : min(abs(p - s.a), abs(p - s.b));
}
//線分と線分の距離
ld dist_ss(Line s, Line t) {
	if (isis_ss(s, t))return 0;
	return min({ dist_sp(s,t.a),dist_sp(s,t.b),dist_sp(t,s.a),dist_sp(t,s.b) });
}
//線分と線分の交点、平行な場合は端点両方
vector<Point> is_ss(Line s1, Line s2) {
	if (!isis_ss(s1, s2))return {};
	vector<Point> res;
	if (abs(cross(s1.b - s1.a, s2.b - s2.a)) < eps) {
		if (isis_sp(s1, s2.a)) res.push_back(s2.a);
		if (isis_sp(s1, s2.b)) res.push_back(s2.b);
		if (isis_sp(s2, s1.a)) res.push_back(s1.a);
		if (isis_sp(s2, s1.b)) res.push_back(s1.b);
	}
	else {
		res.push_back(is_ll(s1, s2));
	}
	return res;
}

//2点の垂直二等分線
Line mid_line(Point a, Point b) {
	ld mx = (real(a) + real(b)) / 2.0, my = (imag(a) + imag(b)) / 2.0;
	ld dx = real(b) - real(a), dy = imag(b) - imag(a);
	swap(dx, dy); dx = -dx;
	Point le = { mx - dx,my - dy }, ri = { mx + dx,my + dy };
	//a,le,ri is counter clockwise
	return { le,ri };
}
//三角形の面積
ld area(Point a, Point b, Point c) {
	ld x1 = real(b) - real(a), y1 = imag(b) - imag(a);
	ld x2 = real(c) - real(a), y2 = imag(c) - imag(a);
	return abs(x1 * y2 - y1 * x2) / 2.0;
}

//直線lに幅dをつける
vector<Line> make_w(Line l, ld d) {
	Point dif = l.b - l.a;
	dif = dif * Point{ 0, 1 };
	dif = dif * (d / abs(dif));
	vector<Line> ret;
	for (int id = -1; id <= 1; id += 2) {
		Point a = l.a + dif * (ld)id;
		Point b = l.b + dif * (ld)id;
		ret.push_back({ a,b });
	}
	return ret;
}

//mid_line of two lines
vector<Line> mid_ll(Line l, Line m) {
	if (!isis_ll(l, m)) {
		ld u = dist_ll(l, m);
		Point d = l.b - l.a;
		Point md = d * exp(Point{ 0,pi / 2.0 });
		Line l_ = { l.a,l.a + md };
		Point ma = is_ll(l_, m);
		Point dif = ma - l.a;
		dif /= 2.0;
		Line res = { l.a + dif,(l.a + dif) + d };
		return { res };
	}
	else {
		Point p = is_ll(l, m);
		ld t1 = arg(l.b - l.a);
		ld t2 = arg(m.b - m.a);
		ld t = (t1 + t2) / 2.0;
		Point dif = { cos(t),sin(t) };
		Point np = p + dif;
		ld d1 = dist_lp(l, np);
		ld d2 = dist_lp(m, np);
		vector<Line> res;
		res.push_back({ p,p + dif });
		t += pi / 2.0;
		dif = { cos(t),sin(t) };
		res.push_back({ p,p + dif });
		return res;
	}
}


void solve() {
	int n; cin >> n;
	vector<int> x(n), y(n);
	rep(i, n)cin >> x[i] >> y[i];
	if (n == 1) {
		cout << 1 << "\n"; return;
	}
	vector<Point> p(n);
	rep(i, n) {
		p[i] = { (ld)x[i],(ld)y[i] };
	}
	vector<Point> vp = p;
	rep(i, n)Rep(j, i + 1, n) {
		rep(k, n)Rep(l, k+1, n) {
			if (P{ i,j } < P{ k,l }) {
				Line l1 = { p[i],p[j] };
				Line l2 = { p[k],p[l] };
				if (isis_ll(l1, l2)) {
					Point c = is_ll(l1, l2);
					bool valid = true;
					for (auto pre : vp) {
						if (abs(pre - c) < eps)valid = false;
					}
					if(valid)
					vp.push_back(c);
				}
			}
		}
	}
	int sz = vp.size();
	//cout << sz << "\n";
	//rep(i, sz)cout << vp[i] << "\n";
	struct edge {
		int to, cost;
	};
	vector<vector<edge>> vs(sz);
	rep(i, sz)Rep(j, i + 1, sz) {
		Line l = { vp[i],vp[j] };
		int val = 0;
		int cnt = 0;
		rep(k, n) {
			if (isis_sp(l, p[k])) {
				val |= (1 << k); cnt++;
			}
		}
		if (cnt >= 2) {
			vs[i].push_back({ j,val });
			vs[j].push_back({ i,val });
		}
	}
	vector<vector<int>> dp(1<<n, vector<int>(sz,mod));
	rep(i, sz) {
		int val = 0;
		rep(j, n) {
			ld d = abs(vp[i] - p[j]);
			if (d < eps) {
				val |= (1 << j);
			}
		}
		dp[val][i] = 0;
	}
	rep(i, (1 << n)) {
		rep(j, sz) {
			if (dp[i][j] == mod)continue;
			for (edge e : vs[j]) {
				int ni = i | e.cost;
				chmin(dp[ni][e.to], dp[i][j] + 1);
			}
		}
	}
	int ans = mod;
	rep(i, sz)chmin(ans, dp[(1 << n) - 1][i]);
	cout << ans << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//expr();
	//while(true)
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

0