結果

問題 No.1045 直方体大学
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-05-01 22:52:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,484 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 205,424 KB
実行使用メモリ 20,024 KB
最終ジャッジ日時 2023-08-26 15:35:38
合計ジャッジ時間 10,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 305 ms
15,672 KB
testcase_09 AC 235 ms
15,600 KB
testcase_10 AC 119 ms
15,664 KB
testcase_11 AC 220 ms
15,824 KB
testcase_12 AC 317 ms
15,668 KB
testcase_13 AC 890 ms
15,628 KB
testcase_14 AC 323 ms
15,656 KB
testcase_15 AC 669 ms
15,640 KB
testcase_16 AC 755 ms
15,612 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, ABC[16][3];
int dp[1 << 16][16][3];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) rep(j, 0, 3) cin >> ABC[i][j];

	rep(msk, 0, 1 << N) rep(lst, 0, N) rep(hei, 0, 3) dp[msk][lst][hei] = -1;
	rep(lst, 0, N) rep(hei, 0, 3) dp[1 << lst][lst][hei] = ABC[lst][hei];

	rep(msk, 0, 1 << N) rep(lst, 0, N) rep(hei, 0, 3) if (0 <= dp[msk][lst][hei]) {
		rep(nxt, 0, N) if (!(msk & (1 << nxt))) rep(hei2, 0, 3) {
			vector<int> other;
			rep(j, 0, 3) if (hei != j) other.push_back(ABC[lst][j]);
			sort(all(other));

			vector<int> other2;
			rep(j, 0, 3) if (hei2 != j) other2.push_back(ABC[nxt][j]);
			sort(all(other2));

			bool ok = false;
			do {
				do {
					if (other2[0] <= other[0] && other2[1] <= other[1]) ok = true;
				} while (next_permutation(all(other2)));
			} while (next_permutation(all(other)));

			if (ok) {
				int msk2 = msk | (1 << nxt);
				chmax(dp[msk2][nxt][hei2], dp[msk][lst][hei] + ABC[nxt][hei2]);
			}
		}
	}

	int ans = -1;
	rep(msk, 0, 1 << N) rep(lst, 0, N) rep(hei, 0, 3) chmax(ans, dp[msk][lst][hei]);
	cout << ans << endl;
}





0