結果

問題 No.1045 直方体大学
ユーザー leaf_1415leaf_1415
提出日時 2020-05-01 22:15:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 644 ms / 2,000 ms
コード長 1,664 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 75,968 KB
実行使用メモリ 28,120 KB
最終ジャッジ日時 2023-08-26 14:35:11
合計ジャッジ時間 7,186 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 604 ms
28,060 KB
testcase_09 AC 644 ms
27,976 KB
testcase_10 AC 622 ms
27,904 KB
testcase_11 AC 623 ms
28,116 KB
testcase_12 AC 588 ms
27,984 KB
testcase_13 AC 562 ms
28,052 KB
testcase_14 AC 587 ms
28,040 KB
testcase_15 AC 589 ms
27,916 KB
testcase_16 AC 568 ms
28,120 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 350 ms
28,000 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0