結果

問題 No.1045 直方体大学
ユーザー roarisroaris
提出日時 2020-05-07 23:55:20
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 1,957 ms
コンパイル使用メモリ 136,200 KB
実行使用メモリ 77,236 KB
最終ジャッジ日時 2023-08-20 15:06:33
合計ジャッジ時間 5,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 5 ms
4,580 KB
testcase_06 AC 5 ms
4,596 KB
testcase_07 AC 4 ms
5,548 KB
testcase_08 AC 330 ms
77,192 KB
testcase_09 AC 335 ms
77,136 KB
testcase_10 AC 309 ms
77,236 KB
testcase_11 AC 318 ms
77,172 KB
testcase_12 AC 316 ms
77,208 KB
testcase_13 AC 318 ms
77,188 KB
testcase_14 AC 334 ms
77,216 KB
testcase_15 AC 332 ms
77,172 KB
testcase_16 AC 317 ms
77,136 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 389 ms
77,224 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> Li;
        Li.pb(make_tuple(A[i], B[i], C[i]));
        Li.pb(make_tuple(A[i], C[i], B[i]));
        Li.pb(make_tuple(B[i], A[i], C[i]));
        Li.pb(make_tuple(B[i], C[i], A[i]));
        Li.pb(make_tuple(C[i], A[i], B[i]));
        Li.pb(make_tuple(C[i], B[i], A[i]));
        L.pb(Li);
    }
    
    rep(i, N) rep(j, 6) {
        int c = get<2>(L[i][j]);
        dp[1<<i][i][j] = c;
    }
    
    rep(S, 1<<N) {
        if (S==0) continue;
        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 (a<=pa && b<=pb) 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