結果

問題 No.1045 直方体大学
ユーザー leaf_1415
提出日時 2020-05-01 22:15:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 612 ms / 2,000 ms
コード長 1,664 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 80,080 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-12-25 12:07:16
合計ジャッジ時間 8,354 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007
using namespace std;
typedef pair<llint, llint> P;
llint n;
llint a[16][3];
llint dp[1<<16][16][3];
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
llint N = 1 << n;
for(int i = 0; i < N; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < 3; k++){
dp[i][j][k] = -inf;
}
}
}
dp[0][0][0] = 0;
for(int i = 0; i < N; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < 3; k++){
llint h = a[j][(k+1)%3], w = a[j][(k+2)%3];
if(i == 0 && j == 0 && k == 0) h = w = inf;
if(h > w) swap(h, w);
for(int l = 0; l < n; l++){
if(i & (1<<l)) continue;
for(int m = 0; m < 3; m++){
llint nh = a[l][(m+1)%3], nw= a[l][(m+2)%3];
if(nh > nw) swap(nh, nw);
if(nh > h || nw > w) continue;
chmax(dp[i|(1<<l)][l][m], dp[i][j][k]+a[l][m]);
}
}
}
}
}
llint ans = 0;
for(int i = 0; i < N; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < 3; k++){
ans = max(ans, dp[i][j][k]);
}
}
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0