結果
問題 | No.2180 Comprehensive Line Segments |
ユーザー |
|
提出日時 | 2023-02-06 14:24:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,293 bytes |
コンパイル時間 | 1,725 ms |
コンパイル使用メモリ | 193,884 KB |
最終ジャッジ日時 | 2025-02-10 11:20:36 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:31:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | for (int i = 0; i < n; ++i) scanf("%d %d", &p[i].x, &p[i].y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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); }