結果

問題 No.1045 直方体大学
ユーザー 👑 hitonanodehitonanode
提出日時 2020-05-01 22:46:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 521 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 84,256 KB
実行使用メモリ 16,252 KB
最終ジャッジ日時 2023-08-26 15:29:04
合計ジャッジ時間 6,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 521 ms
15,968 KB
testcase_09 AC 519 ms
15,988 KB
testcase_10 AC 504 ms
15,984 KB
testcase_11 AC 501 ms
16,252 KB
testcase_12 AC 503 ms
16,016 KB
testcase_13 AC 490 ms
16,080 KB
testcase_14 AC 490 ms
15,932 KB
testcase_15 AC 504 ms
16,008 KB
testcase_16 AC 509 ms
16,020 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 404 ms
16,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

using pint = pair<int, int>;
int main()
{
    int N;
    cin >> N;
    vector<pint> xy(N * 3);
    vector<int> z(N * 3);
    int j = 0;
    for (int i = 0; i < N; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        for (int d = 0; d < 3; d++)
        {
            z[j] = a, xy[j] = make_pair(min(b, c), max(b, c));
            swap(a, b), swap(b, c), j++;
        }
    }
    xy.emplace_back(1e8, 1e8);
    vector<vector<int>> dp(N * 3 + 1, vector<int>(1 << N));
    for (int S = 0; S < (1 << N); S++)
    {
        for (int i = 0; i < N * 3 + 1; i++)
        {
            for (int j = 0; j < N * 3; j++) if (!((S >> (j / 3)) & 1))
            {
                if (xy[i].first < xy[j].first) continue;
                if (xy[i].second < xy[j].second) continue;
                dp[j][S + (1 << (j / 3))] = max(dp[j][S + (1 << (j / 3))], dp[i][S] + z[j]);
            }
        }
    }
    int ret = 0;
    for (auto &vec : dp) ret = max(ret, *max_element(vec.begin(), vec.end()));
    cout << ret << '\n';
}
0