結果

問題 No.1045 直方体大学
ユーザー 259_Momone259_Momone
提出日時 2020-05-01 22:43:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 213,252 KB
実行使用メモリ 17,916 KB
最終ジャッジ日時 2023-08-26 15:27:24
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 18 ms
11,532 KB
testcase_09 AC 14 ms
9,788 KB
testcase_10 AC 9 ms
9,124 KB
testcase_11 AC 12 ms
9,296 KB
testcase_12 AC 18 ms
11,828 KB
testcase_13 AC 42 ms
17,916 KB
testcase_14 AC 16 ms
11,092 KB
testcase_15 AC 34 ms
16,232 KB
testcase_16 AC 39 ms
17,188 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 48 ms
15,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<pair<unsigned long, unsigned long>, unsigned long>> r(N);
    for(auto&& i : r){
        vector v{0, 0, 0};
        cin >> v[0] >> v[1] >> v[2];
        sort(v.begin(), v.end());
        i.first.first = v[0];
        i.first.second = v[1];
        i.second = v[2];
    }
    unsigned long ans{0};
    vector<unordered_map<unsigned long, unsigned long>> dp(1UL << N);
    const auto& enc = [](unsigned long x, unsigned long y) -> unsigned long { return x * 16777216 + y; };
    for(unsigned long i{0}; i < N; ++i){
        ans = max(ans, r[i].second);
        dp[1UL << i][enc(r[i].first.first, r[i].first.second)] = r[i].second;
        dp[1UL << i][enc(r[i].first.first, r[i].second)] = r[i].first.second;
        dp[1UL << i][enc(r[i].first.second, r[i].second)] = r[i].first.first;
    }
    const auto& chmax = [&ans](unsigned long& x, unsigned long a) -> unsigned long { ans = max(ans, a); return x = max(x, a); };
    for(unsigned long j{1}; j < 1UL << N; ++j)for(const auto& [s, h] : dp[j])for(unsigned long i{0}; i < N; ++i)if(!((j >> i) & 1)){
        unsigned long c{1UL << i};
        const auto& [x, y] = make_pair(s / 16777216, s % 16777216);
        if(r[i].first.first <= x && r[i].first.second <= y)chmax(dp[j | c][enc(r[i].first.first, r[i].first.second)], h + r[i].second);
        if(r[i].first.first <= x && r[i].second <= y)chmax(dp[j | c][enc(r[i].first.first, r[i].second)], h + r[i].first.second);
        if(r[i].first.second <= x && r[i].second <= y)chmax(dp[j | c][enc(r[i].first.second, r[i].second)], h + r[i].first.first);
    }
    cout << ans << endl;
    return 0;
}
0