結果

問題 No.1045 直方体大学
ユーザー minatominato
提出日時 2020-05-01 23:10:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 3,279 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 181,096 KB
実行使用メモリ 28,208 KB
最終ジャッジ日時 2023-08-26 15:45:33
合計ジャッジ時間 3,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 51 ms
28,076 KB
testcase_09 AC 49 ms
28,208 KB
testcase_10 AC 46 ms
28,012 KB
testcase_11 AC 48 ms
28,084 KB
testcase_12 AC 49 ms
27,904 KB
testcase_13 AC 57 ms
27,944 KB
testcase_14 AC 49 ms
27,944 KB
testcase_15 AC 56 ms
27,944 KB
testcase_16 AC 55 ms
27,916 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 172 ms
27,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll dp[1<<16][16][3]; //A*B 1, B*C 2, C*A 3
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N),B(N),C(N);
    rep(i,N) cin >> A[i] >> B[i] >> C[i];
    rep(mask,1<<N) rep(i,N) rep(j,3) dp[mask][i][j] = -1e18;
    dp[0][0][0] = 0;

    auto check=[](ll a, ll b, ll c, ll d) {
        if (a < b) swap(a,b);
        if (c < d) swap(c,d);
        return a <= c and b <= d;
    };

    rep(i,N) {
        dp[1<<i][i][0] = C[i];
        dp[1<<i][i][1] = A[i];
        dp[1<<i][i][2] = B[i];
    }
    for (int mask = 1; mask < (1<<N); ++mask) {
        rep(i,N) {
            if (mask&(1<<i)) {
                rep(j,N) {
                    if (mask&(1<<j)) continue;
                    if (dp[mask][i][0] != -1e18) {
                        if (check(A[j],B[j],A[i],B[i])) {
                            chmax(dp[mask+(1<<j)][j][0],dp[mask][i][0]+C[j]);
                        }
                        if (check(B[j],C[j],A[i],B[i])) {
                            chmax(dp[mask+(1<<j)][j][1],dp[mask][i][0]+A[j]);
                        }
                        if (check(C[j],A[j],A[i],B[i])) {
                            chmax(dp[mask+(1<<j)][j][2],dp[mask][i][0]+B[j]);
                        }
                    }
                    if (dp[mask][i][1] != -1e18) {
                        if (check(A[j],B[j],B[i],C[i])) {
                            chmax(dp[mask+(1<<j)][j][0],dp[mask][i][1]+C[j]);
                        }
                        if (check(B[j],C[j],B[i],C[i])) {
                            chmax(dp[mask+(1<<j)][j][1],dp[mask][i][1]+A[j]);
                        }
                        if (check(C[j],A[j],B[i],C[i])) {
                            chmax(dp[mask+(1<<j)][j][2],dp[mask][i][1]+B[j]);
                        }
                    }
                    if (dp[mask][i][2] != -1e18) {
                        if (check(A[j],B[j],C[i],A[i])) {
                            chmax(dp[mask+(1<<j)][j][0],dp[mask][i][2]+C[j]);
                        }
                        if (check(B[j],C[j],C[i],A[i])) {
                            chmax(dp[mask+(1<<j)][j][1],dp[mask][i][2]+A[j]);
                        }
                        if (check(C[j],A[j],C[i],A[i])) {
                            chmax(dp[mask+(1<<j)][j][2],dp[mask][i][2]+B[j]);
                        }
                    }
                }
            }
        }
    }

    ll ans = 0;
    rep(mask,1<<N) rep(i,N) rep(j,3) chmax(ans,dp[mask][i][j]);

    cout << ans << ln;
}
0