結果

問題 No.1045 直方体大学
ユーザー kcvlexkcvlex
提出日時 2020-05-01 22:34:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 3,657 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 149,628 KB
実行使用メモリ 31,192 KB
最終ジャッジ日時 2023-08-26 15:15:52
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,600 KB
testcase_01 AC 2 ms
5,460 KB
testcase_02 AC 2 ms
5,484 KB
testcase_03 AC 2 ms
5,332 KB
testcase_04 AC 1 ms
5,500 KB
testcase_05 AC 2 ms
5,672 KB
testcase_06 AC 2 ms
5,512 KB
testcase_07 AC 2 ms
5,588 KB
testcase_08 AC 20 ms
30,076 KB
testcase_09 AC 16 ms
29,872 KB
testcase_10 AC 11 ms
29,720 KB
testcase_11 AC 14 ms
29,836 KB
testcase_12 AC 20 ms
31,192 KB
testcase_13 AC 39 ms
30,940 KB
testcase_14 AC 19 ms
29,648 KB
testcase_15 AC 34 ms
30,776 KB
testcase_16 AC 35 ms
31,008 KB
testcase_17 AC 2 ms
5,424 KB
testcase_18 AC 268 ms
31,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#include <variant>
#define endl codeforces
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

const std::size_t SIZE = 16;
mdarray<ll, 1 << SIZE, SIZE, 3> dp;
mdarray<bool, 1 << SIZE, SIZE, 3> used;
const ll inf = 5e15;

ll calc(ll s, ll idx, ll sel, const vec<tll> &v) {
    if (idx != -1 && used[s][idx][sel]) return dp[s][idx][sel];
    if (idx != -1) used[s][idx][sel] = true;
    ll ret = 0;
    auto [ a, b, c ] = (idx == -1 ? tll(inf, inf, inf) : v[idx]);
    pll pv[] = { pll(a, b), pll(a, c), pll(b, c), };
    auto [ pa, pb ] = pv[sel];
    for (ll i = 0; i < v.size(); i++) {
        ll mask = 1ll << i;
        if (s & mask) continue;
        auto [ ai, bi, ci ] = v[i];
        pll pvi[] = { pll(ai, bi), pll(ai, ci), pll(bi, ci) };
        ll height[] = { ci, bi, ai, };
        for (ll j = 0; j < 3; j++) {
            auto [ l1, l2 ] = pvi[j];
            bool ok = false;
            if (l1 <= pa && l2 <= pb) ok = true;
            if (l1 <= pb && l2 <= pa) ok = true;
            if (!ok) continue;
            chmax(ret, calc(s | mask, i, j, v) + height[j]);
        }
    }
    if (idx != -1) dp[s][idx][sel] = ret;
    return ret;
}

int main() {
    ll n;
    std::cin >> n;
    vec<tll> abc(n);
    for (auto &&e : abc) {
        ll a, b, c;
        std::cin >> a >> b >> c;
        e = tll(a, b, c);
    }

    std::cout << calc(0, -1, 0, abc) << "\n";
    return 0;
}
0