結果

問題 No.1045 直方体大学
ユーザー roarisroaris
提出日時 2020-05-07 23:58:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 175,292 KB
実行使用メモリ 77,324 KB
最終ジャッジ日時 2023-09-16 08:14:00
合計ジャッジ時間 6,333 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 5 ms
4,588 KB
testcase_06 AC 5 ms
4,620 KB
testcase_07 AC 5 ms
4,592 KB
testcase_08 AC 395 ms
77,188 KB
testcase_09 AC 399 ms
77,256 KB
testcase_10 AC 390 ms
77,180 KB
testcase_11 AC 388 ms
77,000 KB
testcase_12 AC 391 ms
76,972 KB
testcase_13 AC 376 ms
77,016 KB
testcase_14 AC 388 ms
77,324 KB
testcase_15 AC 398 ms
77,156 KB
testcase_16 AC 405 ms
76,984 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 364 ms
77,176 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