結果

問題 No.1045 直方体大学
ユーザー KoD
提出日時 2020-05-01 22:29:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,387 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 90,588 KB
最終ジャッジ日時 2025-01-10 05:09:37
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr int inf = (1 << 30) - 1;

int main() {
  int N;
  std::cin >> N;
  std::vector<std::array<int, 3>> base(N);
  for (auto &arr: base) {
    for (auto &x: arr) {
      std::cin >> x;
    }
    std::sort(arr.rbegin(), arr.rend());
  }
  int ans = 0;
  for (int set: range(0, 1 << N)) {
    auto vec = base;
    for (int i: range(0, N)) {
      if (set >> i & 1) {
        std::swap(vec[i][0], vec[i][1]);
      }
    }
    vec.push_back({ inf, inf, inf });
    std::sort(vec.rbegin(), vec.rend());
    std::vector<std::array<int, 2>> dp(N + 1);
    for (auto &arr: dp) {
      arr.fill(0);
    }
    for (int i: range(1, N + 1)) {
      for (int j: range(0, i)) {
        for (int k: range(0, 2)) {
          int width = vec[i][1 + k];
          int get = vec[i][2 - k];
          for (int l: range(0, 2)) {
            if (vec[j][1 + l] >= width) {
              chmax(dp[i][k], dp[j][l] + get);
            }
          }
        }
      }
    }
    for (const auto &arr: dp) {
      chmax(ans, arr[0]);
      chmax(ans, arr[1]);
    }
  }
  std::cout << ans << '\n';
  return 0;
}
0