結果

問題 No.1045 直方体大学
ユーザー kappybarkappybar
提出日時 2020-05-02 11:54:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 591 ms / 2,000 ms
コード長 1,568 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 179,476 KB
実行使用メモリ 63,088 KB
最終ジャッジ日時 2023-08-28 13:32:34
合計ジャッジ時間 4,881 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 110 ms
62,908 KB
testcase_09 AC 103 ms
62,912 KB
testcase_10 AC 104 ms
63,084 KB
testcase_11 AC 101 ms
63,088 KB
testcase_12 AC 127 ms
62,916 KB
testcase_13 AC 120 ms
62,948 KB
testcase_14 AC 107 ms
62,948 KB
testcase_15 AC 134 ms
62,916 KB
testcase_16 AC 162 ms
62,952 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 591 ms
62,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr int MOD = 1000000007;

struct cube{
    pll surface[3];
    ll height[3];
};

bool ok(cube x,int i,cube y,int j){
    bool res = (x.surface[i].first <= y.surface[j].first && x.surface[i].second <= y.surface[j].second);
    res = res || (x.surface[i].first <= y.surface[j].second && x.surface[i].second <= y.surface[j].first);
    return res;
}

int n;
vector<vector<vector<ll>>> dp;
vector<cube> Cube;

ll dfs(ll mask,int last=-1,int i=-1){
    if(last != -1 && dp[mask][last][i] != -1) return dp[mask][last][i];
    if(mask == (1<<n) -1) return 0;
    ll res = 0;
    for(int next=0;next<n;next++){
        if(mask>>next & 1) continue;
        rep(j,3){
            if(last == -1 or ok(Cube[last],i,Cube[next],j)){
                res = max(res,dfs(mask|(1<<next),next,j) + Cube[next].height[j]);
            }
        }
    }
    if(last == -1) return res;
    return dp[mask][last][i] = res;
}

int main(){
    cin >> n;
    Cube.resize(n);
    rep(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        Cube[i].surface[0] = P(a,b);
        Cube[i].surface[1] = P(b,c);
        Cube[i].surface[2] = P(c,a);
        Cube[i].height[0] = c;
        Cube[i].height[1] = a;
        Cube[i].height[2] = b;
    }
    dp.assign(1<<n,vector<vector<ll>>(n,vector<ll>(3,-1)));


    cout << dfs(0) << endl;

    return 0;
}
0