結果

問題 No.2180 Comprehensive Line Segments
ユーザー SenioriousSeniorious
提出日時 2023-02-06 13:55:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,100 bytes
コンパイル時間 2,913 ms
コンパイル使用メモリ 200,080 KB
実行使用メモリ 5,992 KB
最終ジャッジ日時 2023-09-18 01:29:28
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,832 KB
testcase_01 AC 3 ms
5,768 KB
testcase_02 AC 3 ms
5,792 KB
testcase_03 AC 77 ms
5,788 KB
testcase_04 AC 4 ms
5,724 KB
testcase_05 AC 3 ms
5,988 KB
testcase_06 AC 3 ms
5,956 KB
testcase_07 AC 3 ms
5,728 KB
testcase_08 AC 3 ms
5,720 KB
testcase_09 AC 39 ms
5,716 KB
testcase_10 AC 52 ms
5,848 KB
testcase_11 WA -
testcase_12 AC 28 ms
5,788 KB
testcase_13 AC 77 ms
5,844 KB
testcase_14 AC 73 ms
5,860 KB
testcase_15 WA -
testcase_16 AC 7 ms
5,976 KB
testcase_17 AC 13 ms
5,728 KB
testcase_18 AC 77 ms
5,788 KB
testcase_19 AC 31 ms
5,784 KB
testcase_20 AC 3 ms
5,708 KB
testcase_21 AC 13 ms
5,992 KB
testcase_22 AC 3 ms
5,848 KB
testcase_23 AC 4 ms
5,728 KB
testcase_24 AC 4 ms
5,792 KB
testcase_25 AC 7 ms
5,860 KB
testcase_26 AC 80 ms
5,764 KB
testcase_27 AC 15 ms
5,816 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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 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;
        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)
            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 == 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 sgn(int x) { return (x == 0) ? 0 : ((x > 0) ? 1 : -1); }
0