結果
問題 | No.1045 直方体大学 |
ユーザー | Mister |
提出日時 | 2020-05-01 21:59:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 364 ms / 2,000 ms |
コード長 | 1,655 bytes |
コンパイル時間 | 840 ms |
コンパイル使用メモリ | 80,148 KB |
最終ジャッジ日時 | 2025-01-10 04:46:47 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 |
ソースコード
#include <iostream> #include <vector> template <class T> std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); } void solve() { int n; std::cin >> n; auto ps = vec(n, vec(3, 0)); for (auto& p : ps) { for (auto& x : p) { std::cin >> x; } } auto judge = [&](int ai, int aj, int bi, int bj) { int ax = ps[ai][(aj + 1) % 3], ay = ps[ai][(aj + 2) % 3]; int bx = ps[bi][(bj + 1) % 3], by = ps[bi][(bj + 2) % 3]; if (ax > ay) std::swap(ax, ay); if (bx > by) std::swap(bx, by); return bx <= ax && by <= ay; }; auto dp = vec(1 << n, vec(n, vec(3, -1))); for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { dp[1 << i][i][j] = ps[i][j]; } } int ans = 0; for (int b = 0; b < (1 << n); ++b) { for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { if (dp[b][i][j] == -1) continue; ans = std::max(ans, dp[b][i][j]); for (int ni = 0; ni < n; ++ni) { if ((b >> ni) & 1) continue; int nb = b | (1 << ni); for (int nj = 0; nj < 3; ++nj) { if (!judge(i, j, ni, nj)) continue; dp[nb][ni][nj] = std::max(dp[nb][ni][nj], dp[b][i][j] + ps[ni][nj]); } } } } } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }