結果

問題 No.1045 直方体大学
ユーザー rodearodea
提出日時 2020-05-16 16:59:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 2,940 bytes
コンパイル時間 1,579 ms
コンパイル使用メモリ 122,740 KB
実行使用メモリ 63,140 KB
最終ジャッジ日時 2023-10-23 19:01:41
合計ジャッジ時間 4,171 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 113 ms
63,140 KB
testcase_09 AC 110 ms
63,140 KB
testcase_10 AC 108 ms
63,140 KB
testcase_11 AC 110 ms
63,140 KB
testcase_12 AC 115 ms
63,140 KB
testcase_13 AC 127 ms
63,140 KB
testcase_14 AC 113 ms
63,140 KB
testcase_15 AC 123 ms
63,140 KB
testcase_16 AC 129 ms
63,140 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 263 ms
63,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

bool can_put[20][5][20][5];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<vector<int>> abc(n, vector<int>(3));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++) cin>>abc[i][j];
    }

    for(int pi=0; pi<n; pi++){
        for(int ph=0; ph<3; ph++){
            for(int ni=0; ni<n; ni++){
                for(int nh=0; nh<3; nh++){
                    if(pi == ni) continue;

                    vector<int> v1;
                    for(int i=0; i<3; i++){
                        if(i != ph) v1.emplace_back(abc[pi][i]);
                    }

                    vector<int> v2;
                    for(int i=0; i<3; i++){
                        if(i != nh) v2.emplace_back(abc[ni][i]);
                    }

                    sort(all(v1));
                    sort(all(v2));

                    if((v1[0] >= v2[0] && v1[1] >= v2[1]) || (v1[1] >= v2[0] && v1[0] >= v2[1])) can_put[pi][ph][ni][nh] = true;
                }
            }
        }
    }

    vector<vector<vector<int>>> dp((1<<n), vector<vector<int>>(n, vector<int>(3, -1)));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            dp[1<<i][i][j] = abc[i][j];
        }
    }

    for(int bit=0; bit<(1<<n); bit++){
        for(int pi=0; pi<n; pi++){
            for(int ph=0; ph<3; ph++){
                if(dp[bit][pi][ph] == -1) continue;

                for(int ni=0; ni<n; ni++){
                    if(bit & (1 << ni)) continue;

                    for(int nh=0; nh<3; nh++){
                        if(can_put[pi][ph][ni][nh]){
                            chmax(dp[bit | (1 << ni)][ni][nh], dp[bit][pi][ph] + abc[ni][nh]);
                        }
                    }
                }
            }
        }
    }


    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++){
        for(int i=0; i<n; i++){
            for(int j=0; j<3; j++){
                chmax(ans, dp[bit][i][j]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0