結果

問題 No.1045 直方体大学
ユーザー Y17Y17
提出日時 2020-05-01 23:08:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 173,816 KB
実行使用メモリ 29,200 KB
最終ジャッジ日時 2023-08-26 15:44:47
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
28,976 KB
testcase_01 AC 10 ms
28,940 KB
testcase_02 AC 9 ms
29,032 KB
testcase_03 AC 10 ms
29,200 KB
testcase_04 AC 9 ms
28,968 KB
testcase_05 AC 9 ms
28,944 KB
testcase_06 AC 9 ms
28,976 KB
testcase_07 AC 9 ms
29,012 KB
testcase_08 AC 11 ms
28,944 KB
testcase_09 AC 10 ms
29,100 KB
testcase_10 AC 10 ms
29,004 KB
testcase_11 AC 10 ms
28,964 KB
testcase_12 AC 12 ms
29,132 KB
testcase_13 AC 15 ms
29,016 KB
testcase_14 AC 11 ms
28,944 KB
testcase_15 AC 13 ms
29,036 KB
testcase_16 AC 14 ms
28,940 KB
testcase_17 AC 9 ms
28,960 KB
testcase_18 AC 15 ms
28,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int memo[50][(1 << 16)];

typedef pair<pair<int, int>, pair<int, int>> P;
vector<P> vec;

int dp(int i, int bit){
	bit |= vec[i].second.second;
	if(memo[i][bit] != -1) return memo[i][bit]; 
	int ans = 0;
	int b = vec[i].first.second;
	for(int j = i+1;j < vec.size();j++){
		if(b >= vec[j].first.second && (bit & vec[j].second.second) == 0){
			chmax(ans, dp(j, bit));
		}
	}
	ans += vec[i].second.first;
	return memo[i][bit] = ans;
}

signed main(){
	int n;
	cin >> n;

	for(int i = 0;i < n;i++){
		int a, b, c;
		cin >> a >> b >> c;
		vec.push_back({{min(b, c), max(b, c)}, {a, (1 << i)}});
		vec.push_back({{min(a, c), max(a, c)}, {b, (1 << i)}});
		vec.push_back({{min(a, b), max(a, b)}, {c, (1 << i)}});
	}

	sort(vec.begin(), vec.end(), greater<P>());

	int ans = 0;
	memset(memo, -1, sizeof(memo));
	for(int i = 0;i < vec.size();i++){
		chmax(ans, dp(i, 0));
	}

	cout << ans << endl;

	return 0;
}
0