結果

問題 No.1045 直方体大学
ユーザー MayimgMayimg
提出日時 2020-07-06 14:08:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 208,900 KB
実行使用メモリ 33,352 KB
最終ジャッジ日時 2023-10-24 22:04:16
合計ジャッジ時間 5,559 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,704 KB
testcase_01 AC 3 ms
5,704 KB
testcase_02 AC 3 ms
5,704 KB
testcase_03 AC 3 ms
5,704 KB
testcase_04 AC 2 ms
5,704 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 4 ms
5,724 KB
testcase_18 AC 1,292 ms
33,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:44:25: warning: iteration 5 invokes undefined behavior [-Waggressive-loop-optimizations]
   44 |       vis[1 << i][i][j] = true;
      |       ~~~~~~~~~~~~~~~~~~^~~~~~
main.cpp:43:23: note: within this loop
   43 |     for (int j = 0; j < 6; j++) {
      |                     ~~^~~

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int dp[1 << 16][16][6];
bool vis[1 << 16][16][5];
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;
int n;
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;
}
int rec (int cur, int top, int r) {
  if (cur == 0) return 0;
  if (!((cur >> top) & 1)) return -(1 << 30);
  int& res = dp[cur][top][r];
  if (vis[cur][top][r]) return res;
  vis[cur][top][r] = true;
  int pre = cur ^ (1 << top);
  for (int i = 0; i < n; i++) {
    if ((pre >> i) & 1) {
      for (int j = 0; j < 6; j++) {
        if (canPut(j, r, i, top)) {
          res = max(res, rec(pre, i, j) + a[top][rot[r][2]]);
        }
      }
    }
  }
  return res;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a.push_back({x, y, z});
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      vis[1 << i][i][j] = true;
      dp[1 << i][i][j] = a[i][rot[j][2]];
    }
  }
  for (int i = 0; i < n; i++) for (int j = 0; j < 6; j++) {
    rec((1 << n) - 1, i, j);
  }
  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