結果

問題 No.1045 直方体大学
ユーザー risujirohrisujiroh
提出日時 2020-05-01 21:56:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 795 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 217,072 KB
実行使用メモリ 63,020 KB
最終ジャッジ日時 2023-08-26 09:37:04
合計ジャッジ時間 10,337 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 756 ms
62,952 KB
testcase_09 AC 743 ms
62,940 KB
testcase_10 AC 714 ms
62,944 KB
testcase_11 AC 730 ms
62,968 KB
testcase_12 AC 772 ms
62,952 KB
testcase_13 AC 718 ms
62,936 KB
testcase_14 AC 737 ms
63,020 KB
testcase_15 AC 795 ms
62,992 KB
testcase_16 AC 788 ms
62,880 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 610 ms
62,956 KB
権限があれば一括ダウンロードができます

ソースコード

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