結果

問題 No.1045 直方体大学
ユーザー betrue12betrue12
提出日時 2020-05-01 22:07:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,109 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 204,532 KB
実行使用メモリ 19,784 KB
最終ジャッジ日時 2023-08-26 13:56:59
合計ジャッジ時間 6,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(3));
    for(int i=0; i<N; i++) for(int k=0; k<3; k++) cin >> A[i][k];
    
    static int dp[1<<16][16][3];
    for(int i=0; i<N; i++) for(int k=0; k<3; k++) dp[1<<i][i][k] = A[i][k];

    int ans = 0;

    for(int b=0; b<(1<<N); b++) for(int last=0; last<N; last++) for(int lk=0; lk<3; lk++){
        chmax(ans, dp[b][last][lk]);
        vector<int> prv;
        for(int k=0; k<3; k++) if(k != lk) prv.push_back(A[last][k]);
        if(prv[0] > prv[1]) swap(prv[0], prv[1]);

        for(int i=0; i<N; i++) if(nth_bit(b, i) == 0) for(int nk=0; nk<3; nk++){
            vector<int> nw;
            for(int k=0; k<3; k++) if(k != nk) nw.push_back(A[i][k]);
            if(nw[0] > nw[1]) swap(nw[0], nw[1]);
            if(prv[0] >= nw[0] && prv[1] >= nw[1]) chmax(dp[b+(1<<i)][i][nk], dp[b][last][lk] + A[i][nk]);
        }
    }

    cout << ans << endl;
    return 0;
}
0