結果

問題 No.1045 直方体大学
ユーザー 👑 jupirojupiro
提出日時 2020-05-01 22:31:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 2,199 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 147,064 KB
実行使用メモリ 63,088 KB
最終ジャッジ日時 2023-08-26 15:12:02
合計ジャッジ時間 3,944 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 108 ms
63,032 KB
testcase_09 AC 100 ms
63,048 KB
testcase_10 AC 97 ms
62,992 KB
testcase_11 AC 99 ms
63,024 KB
testcase_12 AC 109 ms
62,984 KB
testcase_13 AC 128 ms
63,088 KB
testcase_14 AC 108 ms
63,044 KB
testcase_15 AC 128 ms
62,928 KB
testcase_16 AC 133 ms
62,992 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 472 ms
63,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int n;
vector<ll> a, b, c;

struct Bottom {
	ll a, b, h;
	Bottom(ll _a, ll _b, ll _h) :a(_a), b(_b), h(_h) {};
};
struct RectangularSolid {

	ll a, b, c;
	vector<Bottom> s;
	RectangularSolid(ll _a, ll _b, ll _c) :a(_a), b(_b), c(_c) {
		s.emplace_back(min(a, b), max(a, b), c);
		s.emplace_back(min(b, c), max(b, c), a);
		s.emplace_back(min(c, a), max(c, a), b);
	}
};
bool check(Bottom bt, Bottom tp) {
	return bt.a >= tp.a and bt.b >= tp.b;
}
vector<RectangularSolid> vr;
vector<vector<vector<ll>>> dp;

ll dfs(ll S, ll pre, ll bt) {
	if (pre != -1 and dp[S][pre][bt] != -1) return dp[S][pre][bt];
	if (S == (1 << n) - 1) return 0;
	ll res = 0;
	for (int bit = 0; bit < n; bit++) {
		if (!(S >> bit & 1)) {
			for (int i = 0; i < 3; i++) {
				if (pre == -1 or check(vr[pre].s[bt], vr[bit].s[i])) {
					chmax(res, dfs(S | (1 << bit), bit, i) + vr[bit].s[i].h);
				}
			}
		}
	}
	if(pre != -1) dp[S][pre][bt] = res;
	return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d", &n);
	a.resize(n), b.resize(n), c.resize(n);
	dp.resize(1 << n, vector<vector<ll>>(n, vector<ll>(3, -1)));
	for (int i = 0; i < n; i++) {
		scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
		vr.emplace_back(a[i], b[i], c[i]);
	}

	cout << dfs(0, -1, -1) << endl;
	return 0;
}
0