結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2020-05-02 00:19:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 152 ms / 2,000 ms |
| コード長 | 2,518 bytes |
| コンパイル時間 | 2,323 ms |
| コンパイル使用メモリ | 199,076 KB |
| 最終ジャッジ日時 | 2025-01-10 05:39:24 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
#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];
bool ok[16][3][16][3];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
rep(i, 0, N) rep(j, 0, 3) cin >> ABC[i][j];
rep(lst, 0, N) rep(hei, 0, 3) rep(nxt, 0, N) rep(hei2, 0, 3) {
vector<int> v1;
rep(j, 0, 3) if (hei != j) v1.push_back(ABC[lst][j]);
sort(all(v1));
vector<int> v2;
rep(j, 0, 3) if (hei2 != j) v2.push_back(ABC[nxt][j]);
sort(all(v2));
if (v2[0] <= v1[0] && v2[1] <= v1[1]) ok[lst][hei][nxt][hei2] = true;
if (v2[1] <= v1[0] && v2[0] <= v1[1]) ok[lst][hei][nxt][hei2] = true;
}
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) {
if (ok[lst][hei][nxt][hei2]) {
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;
}
はまやんはまやん