結果

問題 No.1045 直方体大学
ユーザー saxofone111saxofone111
提出日時 2021-03-09 12:12:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,909 bytes
コンパイル時間 2,460 ms
コンパイル使用メモリ 204,192 KB
実行使用メモリ 30,464 KB
最終ジャッジ日時 2024-04-19 10:15:05
合計ジャッジ時間 3,188 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 29 ms
30,336 KB
testcase_09 AC 26 ms
30,336 KB
testcase_10 AC 25 ms
30,464 KB
testcase_11 AC 25 ms
30,464 KB
testcase_12 AC 27 ms
30,336 KB
testcase_13 AC 28 ms
30,336 KB
testcase_14 AC 27 ms
30,464 KB
testcase_15 AC 31 ms
30,336 KB
testcase_16 AC 30 ms
30,464 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 230 ms
30,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

struct block{
  ll a, b, c;
  P get(ll i){
    if(i==0)return {min(b, c), max(b, c)};
    else if(i==1)return {min(a, c), max(a, c)};
    else return {min(a, b), max(a, b)};
  }

  ll height(ll i){
    if(i==0)return a;
    else if(i==1)return b;
    else return c;
  }
  
};

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  vector<block> v(N);
  rep(i, N){
    cin >> v[i].a >> v[i].b >> v[i].c;
  }
  vector<llvec> m(N*3);
  rep(k, N*3){
    ll i = k/3;
    ll j = k%3;
    auto [a, b] = v[i].get(j);
    rep(l, N*3){
      ll L = l/3;
      ll J = l%3;
      if(i==L)continue;
      auto [A, B] = v[L].get(J);
      if(A<=a and B<=b)m[k].push_back(l);
    }
  }

  vector<llvec> dp(1<<N, llvec(3*N, -1e18));
  ll ans = 0;
  rep(i, N){
    rep(k, 3){
      dp[1<<i][3*i+k] = v[i].height(k);
      ans = max(ans, v[i].height(k));
    }
  }
  rep(i, 1<<N){
    rep(k, 3*N){
      if(dp[i][k]==-1e18)continue;
      for(auto iv: m[k]){
        ll ind = iv/3;
        if((i>>ind)&1){
          continue;
        }else{
          dp[i | (1<<ind)][iv] = max(dp[i | (1<<ind)][iv], dp[i][k] + v[ind].height(iv%3));
          ans = max(ans, dp[i | (1<<ind)][iv]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0