結果
| 問題 | No.2180 Comprehensive Line Segments |
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2022-12-19 15:41:57 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 4,407 bytes |
| 記録 | |
| コンパイル時間 | 2,615 ms |
| コンパイル使用メモリ | 208,816 KB |
| 最終ジャッジ日時 | 2025-02-09 17:04:19 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
/* const double EPS = 1e-10;
struct EpsilonDouble {
double x;
EpsilonDouble(void) {
x = 0.0;
}
EpsilonDouble(double x) {
this->x = x;
}
static EpsilonDouble zero() {
return EpsilonDouble();
}
EpsilonDouble operator+(void) const {
return EpsilonDouble(this->x);
}
EpsilonDouble operator-(void) const {
return EpsilonDouble(-this->x);
}
EpsilonDouble operator+(const EpsilonDouble other) const {
return EpsilonDouble(this->x + other.x);
}
EpsilonDouble operator-(const EpsilonDouble other) const {
return EpsilonDouble(this->x - other.x);
}
EpsilonDouble operator*(const EpsilonDouble other) const {
return EpsilonDouble(this->x * other.x);
}
EpsilonDouble operator/(const EpsilonDouble other) const {
return EpsilonDouble(this->x / other.x);
}
bool operator==(const EpsilonDouble other) const {
return (abs(this->x - other.x) < EPS);
}
bool operator!=(const EpsilonDouble other) const {
return (((*this) == other) == false);
}
bool operator<(const EpsilonDouble other) const {
return ((*this) != other and this->x < other.x);
}
bool operator>(const EpsilonDouble other) const {
return ((*this) != other and this->x > other.x);
}
};
EpsilonDouble abs(EpsilonDouble x) {
if (x < EpsilonDouble::zero()) {
return -x;
}
return x;
} */
int sgn(double x) {
if (x < 0) {
return -1;
}
else if (x > 0) {
return 1;
}
return 0;
}
template <class T>
struct Vector2 {
T x;
T y;
Vector2(void) {
}
Vector2(T x, T y) {
this->x = x;
this->y = y;
}
static Vector2 normalize(Vector2 v) {
T norm = v.x * v.x + v.y * v.y;
return Vector2(v.x * abs(v.x) / norm, v.y * abs(v.y) / norm);
}
static bool same_inclination(Vector2& v1, Vector2& v2) {
return (v1 * v2 == 0 and (v1.x * v2.x > 0 or v1.y * v2.y > 0));
}
Vector2 operator+(const Vector2 other) const {
return Vector2(this->x + other.x, this->y + other.y);
}
Vector2 operator-(const Vector2 other) const {
return Vector2(this->x - other.x, this->y - other.y);
}
T operator*(const Vector2 other) const {
return this->x * other.y - this->y * other.x;
}
bool operator<(const Vector2 other) const {
return tie(this->x, this->y) < tie(other.x, other.y);
}
bool operator==(const Vector2 other) const {
return tie(this->x, this->y) == tie(other.x, other.y);
}
bool operator!=(const Vector2 other) const {
return tie(this->x, this->y) != tie(other.x, other.y);
}
};
int main(void) {
int N; cin >> N;
V<Vector2<double> > P(N);
for (auto& p : P) {
cin >> p.x >> p.y;
}
if (N == 1) {
cout << 1 << endl;
return 0;
}
V<V<Vector2<double> > > vec_lis(N, V<Vector2<double> >(N));
V<V<V<int> > > dp(1 << N, V<V<int> >(N, V<int>(N, N)));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (i == j) {
continue;
}
vec_lis[i][j] = Vector2<double>::normalize(P[j] - P[i]);
dp[(1 << i) | (1 << j)][i][j] = 1;
}
}
int goal = (1 << N) - 1;
for (int b_now = 3; b_now < goal; ++b_now) {
for (int v_prev = 0; v_prev < N; ++v_prev) {
for (int v_now = 0; v_now < N; ++v_now) {
if (v_prev == v_now or dp[b_now][v_prev][v_now] == N or ((b_now >> v_prev) & 1) == 0 or ((b_now >> v_now) & 1) == 0) {
continue;
}
int c_now = dp[b_now][v_prev][v_now], c_next = 0;
Vector2<double>& v1 = vec_lis[v_prev][v_now];
for (int v_next1 = 0; v_next1 < N; ++v_next1) {
for (int v_next2 = 0; v_next2 < N; ++v_next2) {
if (v_next1 == v_next2 or (((b_now >> v_next1) & 1) and v_now != v_next1) or ((b_now >> v_next2) & 1)) {
continue;
}
int b_next = b_now | (1 << v_next1) | (1 << v_next2);
Vector2<double>& v2 = vec_lis[v_now][v_next1], v3 = vec_lis[v_next1][v_next2];
if (v_now == v_next1) {
c_next = c_now + 1 - (v1 == v3);
}
else {
int d = (v1 == v2) + (v2 == v3);
if (d == 0) {
int s1 = sgn(v1 * v2), s2 = sgn(v2 * v3), s3 = sgn(v1 * v3);
d = (s1 == s2 and s2 == s3);
}
c_next = c_now + 2 - d;
}
if (dp[b_next][v_next1][v_next2] <= c_next) {
continue;
}
dp[b_next][v_next1][v_next2] = c_next;
}
}
}
}
}
int ans = N;
for (auto v : dp[goal]) {
for (auto k : v) {
if (ans <= k) {
continue;
}
ans = k;
}
}
cout << ans << endl;
return 0;
}
MasKoaTS