結果

問題 No.1045 直方体大学
ユーザー recososorecososo
提出日時 2020-05-01 22:32:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,595 bytes
コンパイル時間 1,414 ms
コンパイル使用メモリ 173,592 KB
実行使用メモリ 15,952 KB
最終ジャッジ日時 2023-08-26 15:12:29
合計ジャッジ時間 2,541 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 16 ms
15,640 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 24 ms
15,836 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 153 ms
15,720 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]]){
                            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