結果

問題 No.1045 直方体大学
ユーザー optopt
提出日時 2020-05-02 00:34:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 802 ms / 2,000 ms
コード長 2,609 bytes
コンパイル時間 3,128 ms
コンパイル使用メモリ 207,980 KB
実行使用メモリ 63,120 KB
最終ジャッジ日時 2023-08-26 18:20:34
合計ジャッジ時間 10,565 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 737 ms
62,948 KB
testcase_09 AC 736 ms
62,968 KB
testcase_10 AC 741 ms
62,980 KB
testcase_11 AC 740 ms
62,896 KB
testcase_12 AC 744 ms
62,892 KB
testcase_13 AC 731 ms
62,948 KB
testcase_14 AC 748 ms
62,892 KB
testcase_15 AC 802 ms
62,896 KB
testcase_16 AC 749 ms
63,120 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 676 ms
62,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

using VVV = vector<VV>;


int main() {
  ll n; cin >> n;
  VV a(n, V(3)); cin >> a;

  auto f = [&] (int i1, int j1, int i2, int j2) {
    int x1 = a[i1][(j1+1)%3];
    int y1 = a[i1][(j1+2)%3];
    int x2 = a[i2][(j2+1)%3];
    int y2 = a[i2][(j2+2)%3];
    if (x1 > y1) swap(x1, y1);
    if (x2 > y2) swap(x2, y2);
    return (x1 >= x2 && y1 >= y2);
  };

  int N = 1<<n;
  VVV dp(N, VV(n, V(3)));

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

  rep(S, N) rep(i1, n) rep(j1, 3) rep(i2, n) rep(j2, 3) {
    if (__builtin_popcount(S) == 0) continue;
    if (!((S>>i1)&1)) continue;
    if ((S>>i2)&1) continue;
    if (!f(i1, j1, i2, j2)) continue;
    int x = dp[S][i1][j1] + a[i2][j2];
    chmax(dp[S+(1<<i2)][i2][j2], x);
    chmax(ans, x);
  }

  cout << ans << "\n";
  return 0;
}
0