結果

問題 No.1045 直方体大学
ユーザー erbowlerbowl
提出日時 2020-05-06 22:53:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,691 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 207,956 KB
実行使用メモリ 300,176 KB
最終ジャッジ日時 2023-09-16 07:36:13
合計ジャッジ時間 15,587 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 458 ms
299,860 KB
testcase_01 AC 456 ms
299,792 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 461 ms
299,796 KB
testcase_18 AC 716 ms
299,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;


int main() {
    ll n;
    std::cin >> n;
    
    vector<vector<ll>> abc(n,vector<ll>(3,0));
    for (int i = 0; i < n; i++) {
        std::cin >> abc[i][0]>>abc[i][1]>>abc[i][2];
    }
    
    vector<vector<vector<ll>>> dp((1<<18),vector<vector<ll>>(20,vector<ll>(3,0)));
    ll ans = 0;
    // 0 0が高さ
    for (int i = 1; i <= (1<<n); i++) {
        for (int j = 0; j < n; j++) {
            if(!(i & (1<<j)))continue;
            if(__builtin_popcount(i)==1){
                dp[i][j][0] = abc[j][0];
                dp[i][j][1] = abc[j][1];
                dp[i][j][2] = abc[j][2];
                ans = max({
                    ans,
                    abc[j][0],
                    abc[j][1],
                    abc[j][2]
                });
                continue;
            }
            for (int k = 0; k < n; k++) {
                if(!(i & (1<<k)))continue;
                if(j==k)continue;
                auto &d = dp[i][j];
                auto &pd= dp[i&~(1<<j)][k];
                
                for (int ii = 0; ii < 3; ii++) {
                    for (int jj = 0; jj < 3; jj++) {
                        if((abc[j][(ii+1)%3]<=abc[k][(jj+1)%3]&&abc[j][(ii+2)%3]<=abc[k][(jj+2)%3])
                        ||(abc[j][(ii+1)%3]<=abc[k][(jj+2)%3]&&abc[j][(ii+2)%3]<=abc[k][(jj+1)%3])){
                            d[ii] = max(d[ii],pd[jj]+abc[j][jj]); 
                            
                            ans = max(ans,d[ii]);
                        }
                    }
                }
            }
        }
    }
    std::cout << ans << std::endl;
}
0