結果

問題 No.1045 直方体大学
ユーザー roarisroaris
提出日時 2020-05-08 16:51:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 3,993 ms
コンパイル使用メモリ 208,952 KB
実行使用メモリ 77,320 KB
最終ジャッジ日時 2023-09-16 08:30:52
合計ジャッジ時間 9,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 5 ms
4,532 KB
testcase_06 AC 5 ms
4,488 KB
testcase_07 AC 5 ms
4,488 KB
testcase_08 AC 402 ms
77,124 KB
testcase_09 AC 395 ms
77,108 KB
testcase_10 AC 389 ms
77,064 KB
testcase_11 AC 388 ms
77,104 KB
testcase_12 AC 396 ms
77,144 KB
testcase_13 AC 374 ms
77,276 KB
testcase_14 AC 396 ms
77,320 KB
testcase_15 AC 401 ms
77,104 KB
testcase_16 AC 410 ms
77,072 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 378 ms
77,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef tuple<int, int, int> T;

int N;
int A[18], B[18], C[18];
vector<vector<T>> L;
int dp[1<<18][18][8];

signed main() {
    cin >> N;
    rep(i, N) cin >> A[i] >> B[i] >> C[i];
    rep(i, N) {
        vector<T> v;
        v.pb(make_tuple(A[i], B[i], C[i]));
        v.pb(make_tuple(A[i], C[i], B[i]));
        v.pb(make_tuple(B[i], A[i], C[i]));
        v.pb(make_tuple(B[i], C[i], A[i]));
        v.pb(make_tuple(C[i], A[i], B[i]));
        v.pb(make_tuple(C[i], B[i], A[i]));
        L.pb(v);
    }
    
    rep(i, N) rep(j, 6) dp[1<<i][i][j] = get<2>(L[i][j]);
    rep(S, 1<<N) {
        rep(i, N) {
            if (!((S>>i)&1)) continue;
            rep(j, N) {
                if ((S>>j)&1) continue;
                rep(k, 6) rep(l, 6) {
                    int pa = get<0>(L[i][k]), pb = get<1>(L[i][k]);
                    int a = get<0>(L[j][l]), b = get<1>(L[j][l]), c = get<2>(L[j][l]);
                    if (pa>=a && pb>=b) dp[S|(1<<j)][j][l] = max(dp[S|(1<<j)][j][l], dp[S][i][k]+c);
                }
            }
        }
    }
    
    int ans = 0;
    rep(S, 1<<N) rep(i, N) rep(j, 6) ans = max(ans, dp[S][i][j]);
    cout << ans << endl;
}
0