結果

問題 No.2180 Comprehensive Line Segments
ユーザー SenioriousSeniorious
提出日時 2023-02-06 14:24:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,293 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 201,368 KB
実行使用メモリ 6,100 KB
最終ジャッジ日時 2023-09-18 01:53:22
合計ジャッジ時間 4,182 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,792 KB
testcase_01 AC 3 ms
5,908 KB
testcase_02 AC 3 ms
5,864 KB
testcase_03 AC 57 ms
5,912 KB
testcase_04 AC 3 ms
5,844 KB
testcase_05 AC 3 ms
5,848 KB
testcase_06 AC 3 ms
5,920 KB
testcase_07 AC 3 ms
5,856 KB
testcase_08 AC 3 ms
5,916 KB
testcase_09 AC 28 ms
5,776 KB
testcase_10 AC 34 ms
5,844 KB
testcase_11 AC 60 ms
5,860 KB
testcase_12 AC 22 ms
5,776 KB
testcase_13 AC 59 ms
5,868 KB
testcase_14 AC 51 ms
5,856 KB
testcase_15 AC 67 ms
5,792 KB
testcase_16 AC 6 ms
5,852 KB
testcase_17 AC 11 ms
5,844 KB
testcase_18 AC 59 ms
5,856 KB
testcase_19 AC 23 ms
5,852 KB
testcase_20 AC 3 ms
5,780 KB
testcase_21 AC 10 ms
5,792 KB
testcase_22 AC 3 ms
5,852 KB
testcase_23 AC 4 ms
6,100 KB
testcase_24 AC 3 ms
5,840 KB
testcase_25 AC 5 ms
5,912 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 10 ms
5,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;

const int N = 12;

class Point {
 public:
  using Vector = Point;
  int x, y;
  Point(int x = 0, int y = 0) : x(x), y(y) {}
  friend Vector operator-(const Point &a, const Point &b) { return Vector(a.x - b.x, a.y - b.y); }
} p[N];
using Vector = Point;

int cross(const Vector &a, const Vector &b);
int dot(const Vector &a, const Vector &b);
int sgn(int x);
void upd(int &a, const int &b) { a = std::min(a, b); }

int dp[1 << N][N][N];
int n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d %d", &p[i].x, &p[i].y);
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      dp[(1 << i) | (1 << j)][i][j] = 1;
    }
  }
  for (int s = 0; s < 1 << n; ++s) {
    for (int i = 0; i < n; ++i) {
      if (~s >> i & 1) continue;
      for (int j = 0; j < n; ++j) {
        if (~s >> j & 1) continue;
        if (i == j) continue;
        int now = dp[s][i][j];
        for (int k = 0; k < n; ++k) {
          if (s >> k & 1) continue;
          if (sgn(cross(p[j] - p[i], p[k] - p[j])) == 0 && dot(p[j] - p[i], p[k] - p[j]) >= 0)
            upd(dp[s | (1 << k)][j][k], now);
          else
            upd(dp[s | (1 << k)][j][k], now + 1);
          for (int l = 0; l < n; ++l) {
            if (s >> l & 1) continue;
            if (l == k) continue;
            int s1 = sgn(cross(p[j] - p[i], p[k] - p[j]));
            int s2 = sgn(cross(p[k] - p[j], p[l] - p[k]));
            int s3 = sgn(cross(p[j] - p[i], p[l] - p[k]));
            if (s1 && s1 == s2 && s2 == s3) upd(dp[s | (1 << k) | (1 << l)][k][l], now + 1);
          }
        }
      }
    }
  }
  int ans = n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      ans = std::min(ans, dp[(1 << n) - 1][i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}

int cross(const Vector &a, const Vector &b) { return a.x * b.y - a.y * b.x; }
int dot(const Vector &a, const Vector &b) { return a.x * b.x + a.y * b.y; }
int sgn(int x) { return (x == 0) ? 0 : ((x > 0) ? 1 : -1); }
0