結果

問題 No.1045 直方体大学
ユーザー firiexpfiriexp
提出日時 2020-05-01 23:32:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,574 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 100,164 KB
最終ジャッジ日時 2024-04-27 03:11:32
合計ジャッジ時間 1,242 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:34:24: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
   34 |             cin >> A[i][j];
      |                        ^
main.cpp:46:58: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
   46 |                         if(k != m) tmp1.emplace_back(A[i][m]);
      |                                                          ^
main.cpp:47:58: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
   47 |                         if(l != m) tmp2.emplace_back(A[j][m]);
      |                                                          ^
main.cpp:49:93: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
   49 |                     if(tmp1[0] <= tmp2[0] && tmp1[1] <= tmp2[1]) chmax(dp0[i][j][k][l], A[j][l]);
      |                                                                                             ^
main.cpp:50:93: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
   50 |                     if(tmp1[0] <= tmp2[1] && tmp1[1] <= tmp2[0]) chmax(dp0[i][j][k][l], A[j][l]);
      |                                                                                             ^
main.cpp:57:36: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    vector<array<int, 3>> A(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> A[i][j];
        }
    }
    auto dp = make_v(1 << n, n, 3, 0);
    auto dp0 = make_v(n, n, 3, 3, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i == j) continue;
            for (int k = 0; k < 3; ++k) {
                for (int l = 0; l < 3; ++l) {
                    vector<int> tmp1, tmp2;
                    for (int m = 0; m < 3; ++m) {
                        if(k != m) tmp1.emplace_back(A[i][m]);
                        if(l != m) tmp2.emplace_back(A[j][m]);
                    }
                    if(tmp1[0] <= tmp2[0] && tmp1[1] <= tmp2[1]) chmax(dp0[i][j][k][l], A[j][l]);
                    if(tmp1[0] <= tmp2[1] && tmp1[1] <= tmp2[0]) chmax(dp0[i][j][k][l], A[j][l]);
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            dp[1 << i][i][j] = A[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 3; ++k) {
                if(dp[i][j][k]){
                    chmax(ans, dp[i][j][k]);
                    for (int l = 0; l < n; ++l) {
                        if(!(i & (1 << l))){
                            for (int m = 0; m < 3; ++m) {
                                if(dp0[j][l][k][m]){
                                    chmax(dp[i^(1 << l)][l][m], dp[i][j][k]+dp0[j][l][k][m]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
0