結果

問題 No.1045 直方体大学
ユーザー stoqstoq
提出日時 2021-08-04 20:30:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,500 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 210,976 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-14 21:24:37
合計ジャッジ時間 3,280 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define MOD_TYPE 1

#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#if 0
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using extset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename T>
using smaller_queue = priority_queue<T, vector<T>, greater<T>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-7;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
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;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

random_device seed_gen;
mt19937_64 engine(seed_gen());

// --------------------------------------

template <typename T>
struct BellmanFord
{
  struct edge
  {
    int from, to;
    T cost;
  };

  int V;
  T INF;
  vector<edge> E;
  vector<T> d;
  vector<bool> negative;

  BellmanFord(int V, T INF = 4e18) : V(V), d(V), negative(V) {}

  void add_edge(int a, int b, T c, bool directed = true)
  {
    E.push_back(edge{a, b, c});
    if (!directed)
      E.push_back(edge{b, a, c});
  }

  void calc(int s)
  {
    fill(all(d), INF);
    d[s] = 0;
    bool update;
    while (1)
    {
      update = false;
      for (auto e : E)
      {
        if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
        {
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if (!update)
        return;
    }
  }

  bool calc_and_find_negative_loop(int s, int g = -1)
  {
    fill(all(d), INF);
    fill(all(negative), false);
    d[s] = 0;

    rep(i, V)
    {
      bool update = false;
      for (auto e : E)
      {
        if (d[e.from] != LINF && d[e.to] > d[e.from] + e.cost)
        {
          d[e.to] = d[e.from] + e.cost;
          update = true;
          if (i == V - 1)
            negative[e.from] = negative[e.to] = true;
        }
      }
      if (!update)
        return false;
    }
    if (g == -1)
    {
      rep(i, V)
      {
        if (negative[i])
          return true;
      }
      return false;
    }
    else
    {
      return negative[g];
    }
  }

  bool find_any_negative_loop()
  {
    vector<T> d_(V);
    rep(i, V) for (auto e : E)
    {
      if (d_[e.to] > d_[e.from] + e.cost)
      {
        d_[e.to] = d_[e.from] + e.cost;
        if (i == V - 1)
          return true;
      }
    }
    return false;
  }
};

void solve()
{
  int n;
  cin >> n;
  int a[16][3];
  rep(i, n) rep(j, 3) cin >> a[i][j];
  BellmanFord<int> bf(n * 3 + 1, INF);
  const int S = n * 3;
  rep(i, n) rep(j, n)
  {
    if (i == j)
      continue;
    if (a[i][0] >= a[j][0] and a[i][1] >= a[j][1])
      ;
    rep(k, 3) rep(l, 3)
    {
      int h1 = a[i][k], h2 = a[j][l];
      int a1, b1;
      if (k == 0)
        a1 = a[i][1], b1 = a[i][2];
      if (k == 1)
        a1 = a[i][0], b1 = a[i][2];
      if (k == 2)
        a1 = a[i][0], b1 = a[i][1];
      int a2, b2;
      if (l == 0)
        a2 = a[j][1], b2 = a[j][2];
      if (l == 1)
        a2 = a[j][0], b2 = a[j][2];
      if (l == 2)
        a2 = a[j][0], b2 = a[j][1];
      if (a1 < a2 and b1 < b2 or a1 < b2 and b1 < a2)
        bf.add_edge(i + n * k, j + n * l, -h2);
    }
  }
  rep(i, n) rep(k, 3)
  {
    bf.add_edge(S, i + n * k, -a[i][k]);
  }
  bf.calc(S);
  int ans = 0;
  rep(i, n * 3) chmax(ans, -bf.d[i]);
  cout << ans << "\n";
}

int main()
{
  solve();
}
0