結果

問題 No.1045 直方体大学
ユーザー micheeeeell1001micheeeeell1001
提出日時 2020-05-01 23:06:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,033 ms / 2,000 ms
コード長 3,338 bytes
コンパイル時間 2,725 ms
コンパイル使用メモリ 243,856 KB
実行使用メモリ 97,868 KB
最終ジャッジ日時 2023-08-26 15:43:14
合計ジャッジ時間 13,379 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 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,376 KB
testcase_05 AC 7 ms
4,384 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 983 ms
97,732 KB
testcase_09 AC 968 ms
97,796 KB
testcase_10 AC 955 ms
97,776 KB
testcase_11 AC 954 ms
97,748 KB
testcase_12 AC 967 ms
97,764 KB
testcase_13 AC 952 ms
97,868 KB
testcase_14 AC 956 ms
97,720 KB
testcase_15 AC 987 ms
97,780 KB
testcase_16 AC 1,001 ms
97,712 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 1,033 ms
97,680 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: ラムダ関数内:
main.cpp:108:5: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
  108 |     };
      |     ^

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void print() {
    cout << endl;
}

// template <class Head, class... Tail>
// void print(Head&& head, Tail&&... tail) {
//     cout << head;
//     if (sizeof...(tail) != 0) cout << " ";
//     print(forward<Tail>(tail)...);
// }

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i,k-1)cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    cout << p.first << " " << p.second << "\n";
}


template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

struct state{
    ll x,y,z;
    state(){}
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector<state> v(n);
    rep(i,n)cin >> v[i].x >> v[i].y >> v[i].z;

    auto c = [&](ll j, ll k, ll l, ll m){
        ll one[2], two[2];
        if(k == 0){
            one[0] = v[j].x, one[1] = v[j].y;
        }
        if(k == 1){
            one[0] = v[j].z, one[1] = v[j].y;
        }
        if(k == 2){
            one[0] = v[j].x, one[1] = v[j].z;
        }
        if(m == 0){
            two[0] = v[l].x, two[1] = v[l].y;
        }
        if(m == 1){
            two[0] = v[l].z, two[1] = v[l].y;
        }
        if(m == 2){
            two[0] = v[l].x, two[1] = v[l].z;
        }
        if(one[0] >= two[0] && one[1] >= two[1])return true;
        if(one[0] >= two[1] && one[1] >= two[0])return true;
        return false;
    };
    auto f = [&](ll l, ll m){
        if(m == 0)return v[l].z;
        if(m == 1)return v[l].x;
        if(m == 2)return v[l].y;
    };
    vvvl dp(1 << n, vvl(n, vl(3)));
    rep(i,n){
        rep(j, 3)dp[1LL << i][i][j] = f(i, j);
    }
    rep(i, 1LL << n){
        rep(j,n){
            if((i >> j) & 1){

                rep(k, 3){
                    rep(l,n){
                        if((i >> l) & 1)continue;
                        rep(m,3){
                            if(c(j,k,l,m)){
                                chmax(dp[i | (1LL << l)][l][m], dp[i][j][k] + f(l,m));
                            }
                        }
                    }
                }
            }
        }
        // print(dp[i]);print();
    }

    ll ans = 0;
    rep(i, 1LL << n){
        rep(j,n)rep(k,3)chmax(ans, dp[i][j][k]);
    }

    cout << ans << endl;
}
0