結果

問題 No.1045 直方体大学
ユーザー KoDKoD
提出日時 2020-05-01 22:44:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,538 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 92,232 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 15:27:43
合計ジャッジ時間 2,985 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 133 ms
4,376 KB
testcase_09 AC 132 ms
4,376 KB
testcase_10 AC 135 ms
4,380 KB
testcase_11 AC 117 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 131 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 59 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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) {
    arr = {};
    for (auto &x: arr) {
      std::cin >> x;
    }
    std::sort(arr.rbegin(), arr.rend());
  }
  int ans = -inf;
  for (int set: range(0, 1 << N)) {
    std::vector<std::array<int, 4>> vec;
    for (int i: range(0, N)) {
      if (set >> i & 1) {
        vec.push_back({ base[i][1], base[i][2], base[i][0], i });
      }
      else {
        if (base[i][1] != base[i][2]) {
          vec.push_back({ base[i][0], base[i][1], base[i][2], i });
          vec.push_back({ base[i][0], base[i][2], base[i][1], i });
        }
        else {
          vec.push_back({ base[i][0], base[i][1], base[i][2], i });
        }
      }
    }
    vec.push_back({ inf, inf, inf, -1 });
    std::sort(vec.rbegin(), vec.rend());
    std::vector<int> dp(vec.size(), -inf);
    dp.front() = 0;
    for (int i: range(1, vec.size())) {
      for (int j: range(0, i)) {
        if (vec[j][1] >= vec[i][1] && vec[j][3] != vec[i][3]) {
          chmax(dp[i], dp[j] + vec[i][2]);
        }
      }
    }
    chmax(ans, *std::max_element(dp.begin(), dp.end()));
  }
  std::cout << ans << '\n';
  return 0;
}
0