結果

問題 No.1045 直方体大学
ユーザー leaf_1415leaf_1415
提出日時 2020-05-01 22:12:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,664 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 76,196 KB
実行使用メモリ 28,192 KB
最終ジャッジ日時 2023-08-26 14:17:33
合計ジャッジ時間 4,789 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 2 ms
4,380 KB
testcase_18 AC 201 ms
27,940 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][(k+1)%3], nw= a[l][(k+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