結果

問題 No.1045 直方体大学
ユーザー momoyuumomoyuu
提出日時 2023-03-16 01:36:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 2,047 bytes
コンパイル時間 2,973 ms
コンパイル使用メモリ 254,924 KB
実行使用メモリ 63,300 KB
最終ジャッジ日時 2023-10-18 12:46:40
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 309 ms
63,300 KB
testcase_09 AC 313 ms
63,300 KB
testcase_10 AC 307 ms
63,300 KB
testcase_11 AC 305 ms
63,300 KB
testcase_12 AC 312 ms
63,300 KB
testcase_13 AC 304 ms
63,300 KB
testcase_14 AC 308 ms
63,300 KB
testcase_15 AC 307 ms
63,300 KB
testcase_16 AC 314 ms
63,300 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 281 ms
63,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool ok(int a,int b,int c,int d){
    if(a>=c&&b>=d) return true;
    if(a>=d&&b>=c) return true;
    return false;
    return (a>=c&&b>=d) || (a>=d&&b>=c);
}

#define chmax(a,b) a = max(a,b)

int main(){
    int n;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    for(int i = 0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    vector<vector<vector<ll> > > dp(1<<n,vector<vector<ll> >(n,vector<ll>(3,0)));
    for(int i = 0;i<n;i++){
        dp[1<<i][i][0] = a[i];
        dp[1<<i][i][1] = b[i];
        dp[1<<i][i][2] = c[i];
    }
    
    ll ans = 0;
    for(int i = 0;i<1<<n;i++){
        for(int j = 0;j<n;j++){
            if(!(i>>j&1)) continue;
            ans = max(ans,dp[i][j][0]);
            ans = max(ans,dp[i][j][1]);
            ans = max(ans,dp[i][j][2]);
            for(int k = 0;k<n;k++){
                if(i>>k&1) continue;
                int a1,a2;
                for(int l = 0;l<3;l++){
                    if(l==0){
                        a1 = b[j];
                        a2 = c[j];
                    }else if(l==1){
                        a1 = a[j];
                        a2 = c[j];
                    }else{
                        a1 = a[j];
                        a2 = b[j];
                    }
                    int b1,b2;
                    ll h;
                    for(int L = 0;L<3;L++){
                        if(L==0){
                            h = a[k];
                            b1 = b[k];
                            b2 = c[k];
                        }else if(L==1){
                            b1 = a[k];
                            b2 = c[k];
                            h = b[k];
                        }else{
                            h = c[k];
                            b1 = a[k];
                            b2 = b[k];
                        }
                        if(ok(a1,a2,b1,b2)) chmax(dp[i|1<<k][k][L],dp[i][j][l]+h);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

0