結果
| 問題 | No.1045 直方体大学 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-06 14:08:05 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,482 bytes |
| 記録 | |
| コンパイル時間 | 2,104 ms |
| コンパイル使用メモリ | 200,140 KB |
| 最終ジャッジ日時 | 2025-01-11 16:15:12 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 12 |
コンパイルメッセージ
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++) {
| ~~^~~
ソースコード
#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;
}