結果

問題 No.1045 直方体大学
ユーザー IKyoproIKyopro
提出日時 2020-05-01 22:53:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 203,508 KB
実行使用メモリ 15,992 KB
最終ジャッジ日時 2023-08-26 15:36:09
合計ジャッジ時間 6,671 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_18 AC 358 ms
15,720 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!=a){
            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