結果

問題 No.1045 直方体大学
ユーザー betrue12betrue12
提出日時 2020-05-01 22:11:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 203,328 KB
実行使用メモリ 15,820 KB
最終ジャッジ日時 2023-08-26 14:13:12
合計ジャッジ時間 6,303 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 373 ms
15,696 KB
testcase_09 AC 377 ms
15,820 KB
testcase_10 AC 365 ms
15,696 KB
testcase_11 AC 369 ms
15,652 KB
testcase_12 AC 364 ms
15,696 KB
testcase_13 AC 355 ms
15,640 KB
testcase_14 AC 356 ms
15,636 KB
testcase_15 AC 367 ms
15,648 KB
testcase_16 AC 360 ms
15,696 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 287 ms
15,648 KB
権限があれば一括ダウンロードができます

ソースコード

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];

    int X[16][3][2];
    for(int i=0; i<N; i++) for(int k=0; k<3; k++){
        for(int t=0; t<2; t++) X[i][k][t] = A[i][(k+t+1)%3];
        if(X[i][k][0] > X[i][k][1]) swap(X[i][k][0], X[i][k][1]);
    }
    
    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]);

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

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