結果

問題 No.1045 直方体大学
ユーザー IKyoproIKyopro
提出日時 2020-05-01 22:54:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 204,096 KB
実行使用メモリ 15,876 KB
最終ジャッジ日時 2023-08-26 15:36:48
合計ジャッジ時間 6,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 372 ms
15,752 KB
testcase_09 AC 380 ms
15,624 KB
testcase_10 AC 364 ms
15,596 KB
testcase_11 AC 375 ms
15,612 KB
testcase_12 AC 364 ms
15,616 KB
testcase_13 AC 361 ms
15,820 KB
testcase_14 AC 392 ms
15,876 KB
testcase_15 AC 379 ms
15,716 KB
testcase_16 AC 400 ms
15,656 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 309 ms
15,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

void chmax(int &a,int b){if(a<b) a = b;}

int dp[1<<16][16][3] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vvec<int> A(N,vec<int>(3));
    for(int i=0;i<N;i++) for(int j=0;j<3;j++) cin >> A[i][j];

    auto check = [&](int i,int a,int j,int b){
        int mi1 = 1e9,ma1 = 0;
        for(int k=0;k<3;k++) if(k!=a){
            mi1 = min(mi1,A[i][k]);
            ma1 = max(ma1,A[i][k]);
        }
        int mi2 = 1e9,ma2 = 0;
        for(int k=0;k<3;k++) if(k!=b){
            mi2 = min(mi2,A[j][k]);
            ma2 = max(ma2,A[j][k]);
        }
        return mi1>=mi2 && ma1>=ma2;
    };

    int ans = 0;
    for(int i=0;i<N;i++){
        for(int k=0;k<3;k++){
            dp[1<<i][i][k] = A[i][k];
            ans = max(ans,A[i][k]);
        }
    }

    for(int S=1;S<(1<<N);S++) for(int i=0;i<N;i++) if(S>>i&1){
        for(int j=0;j<N;j++) if(!(S>>j&1)){
            int T = S^(1<<j);
            for(int a=0;a<3;a++) for(int b=0;b<3;b++) if(check(i,a,j,b)){
                chmax(dp[T][j][b],dp[S][i][a]+A[j][b]);
                ans = max(ans,dp[T][j][b]);
            }
        }
    }
    cout << ans << "\n";
}
0