結果

問題 No.1045 直方体大学
ユーザー recososorecososo
提出日時 2020-05-01 22:39:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 172,840 KB
実行使用メモリ 15,908 KB
最終ジャッジ日時 2023-08-26 15:22:58
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 19 ms
15,700 KB
testcase_09 AC 16 ms
15,720 KB
testcase_10 AC 13 ms
15,776 KB
testcase_11 AC 16 ms
15,844 KB
testcase_12 AC 19 ms
15,720 KB
testcase_13 AC 34 ms
15,908 KB
testcase_14 AC 20 ms
15,720 KB
testcase_15 AC 31 ms
15,700 KB
testcase_16 AC 33 ms
15,672 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 196 ms
15,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<vector<int>> a(n,vector<int>(3));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
        sort(a[i].begin(),a[i].end());
    }
    int dp[1<<n][n][3]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            dp[1<<i][i][j]=a[i][j];
        }
    }
    int p[3]={1,0,0};
    int q[3]={2,2,1};
    for(int i=1;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<3;k++){
                if(dp[i][j][k]==0){
                    continue;
                }
                for(int l=0;l<n;l++){
                    if(i&(1<<l)){
                        continue;
                    }
                    for(int m=0;m<3;m++){
                        if(a[l][p[m]]<=a[j][p[k]]&&a[l][q[m]]<=a[j][q[k]]){
                            chmax(dp[i|(1<<l)][l][m],dp[i][j][k]+a[l][m]);
                        }
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<3;k++){
                chmax(ans,dp[i][j][k]);
            }
        }
    }
    cout << ans << endl;
}
0