結果

問題 No.1045 直方体大学
ユーザー risujirohrisujiroh
提出日時 2020-05-01 21:56:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 862 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 2,820 ms
コンパイル使用メモリ 210,564 KB
最終ジャッジ日時 2025-01-10 04:43:58
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmax = [](auto&& a, auto b) { return a < b ? a = b, 1 : 0; };

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<array<int, 3>> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  array<int, 3> p{0, 1, 2};
  vector<array<int, 3>> ps;
  do {
    ps.push_back(p);
  } while (next_permutation(begin(p), end(p)));
  map<array<int, 3>, int> mp;
  for (int t = 0; t < 6; ++t) {
    mp[ps[t]] = t;
  }
  vector dp(1 << n, vector(n, vector(6, -inf<int>)));
  for (int i = 0; i < n; ++i) {
    for (int t = 0; t < 6; ++t) {
      dp[1 << i][i][t] = a[i][ps[t][2]];
    }
  }
  for (int bt = 1; bt < 1 << n; ++bt) {
    for (int i = 0; i < n; ++i) {
      if (~bt >> i & 1) continue;
      for (int t = 0; t < 6; ++t) {
        for (int j = 0; j < n; ++j) {
          if (bt >> j & 1) continue;
          for (int nt = 0; nt < 6; ++nt) {
            if (a[j][ps[nt][0]] > a[i][ps[t][0]]) continue;
            if (a[j][ps[nt][1]] > a[i][ps[t][1]]) continue;
            chmax(dp[bt | 1 << j][j][nt], dp[bt][i][t] + a[j][ps[nt][2]]);
          }
        }
      }
    }
  }
  int res = -inf<int>;
  for (int bt = 0; bt < 1 << n; ++bt) {
    for (int i = 0; i < n; ++i) {
      for (int t = 0; t < 6; ++t) {
        chmax(res, dp[bt][i][t]);
      }
    }
  }
  cout << res << '\n';
}
0