結果

問題 No.1045 直方体大学
ユーザー MayimgMayimg
提出日時 2020-07-06 14:58:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 796 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 209,192 KB
実行使用メモリ 28,252 KB
最終ジャッジ日時 2023-10-24 22:04:54
合計ジャッジ時間 4,567 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
28,252 KB
testcase_01 AC 9 ms
28,252 KB
testcase_02 AC 9 ms
28,252 KB
testcase_03 AC 9 ms
28,252 KB
testcase_04 AC 9 ms
28,252 KB
testcase_05 AC 10 ms
28,252 KB
testcase_06 AC 10 ms
28,252 KB
testcase_07 AC 10 ms
28,252 KB
testcase_08 AC 64 ms
28,252 KB
testcase_09 AC 53 ms
28,252 KB
testcase_10 AC 41 ms
28,252 KB
testcase_11 AC 51 ms
28,252 KB
testcase_12 AC 64 ms
28,252 KB
testcase_13 AC 129 ms
28,252 KB
testcase_14 AC 65 ms
28,252 KB
testcase_15 AC 107 ms
28,252 KB
testcase_16 AC 118 ms
28,252 KB
testcase_17 AC 9 ms
28,252 KB
testcase_18 AC 796 ms
28,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int dp[1 << 16][16][6];
vector<vector<int>> rot = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
vector<vector<int>> a;
bool canPut (int rb, int ru, int ib, int iu) {
  bool ok = true;
  for (int i = 0; i < 2; i++) {
    ok &= a[ib][rot[rb][i]] >= a[iu][rot[ru][i]];
  }
  return ok;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a.push_back({x, y, z});
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      dp[1 << i][i][j] = a[i][rot[j][2]];
    }
  }
  for (int mask = 0; mask < (1 << n); mask++) for (int top = 0; top < n; top++) for (int r = 0; r < 6; r++) {
    if (dp[mask][top][r] == -1) continue;
    for (int i = 0; i < n; i++) if (!((mask >> i) & 1)) {
      for (int j = 0; j < 6; j++) {
        if (canPut(r, j, top, i)) {
          dp[mask | (1 << i)][i][j] = max(dp[mask | (1 << i)][i][j], dp[mask][top][r] + a[i][rot[j][2]]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) for (int j = 0; j < n; j++) for (int k = 0; k < 6; k++) {
    ans = max(ans, dp[i][j][k]);
  }
  cout << ans << endl;
  return 0;
}
0