結果

問題 No.783 門松計画
ユーザー MisterMister
提出日時 2020-08-05 16:35:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 18:46:03
合計ジャッジ時間 1,971 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 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,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int L = 50;
constexpr int INF = 1 << 30;

bool judge(int a, int b, int c) {
    return ((a < b && b > c) || (a > b && b < c)) && a != c;
}

void solve() {
    int n, c;
    std::cin >> n >> c;

    std::vector<std::pair<int, int>> ps(n);
    for (auto& [l, w] : ps) {
        std::cin >> l;
        --l;
    }
    for (auto& [l, w] : ps) std::cin >> w;

    auto dp = vec(L, vec(L, vec(c + 1, -INF)));
    for (auto [l1, w1] : ps) {
        for (auto [l2, w2] : ps) {
            if (l1 == l2 || w1 + w2 > c) continue;
            dp[l1][l2][w1 + w2] = std::max(dp[l1][l2][w1 + w2], l1 + l2 + 2);
        }
    }

    int ans = 0;
    for (int p = 0; p <= c; ++p) {
        for (int l1 = 0; l1 < L; ++l1) {
            for (int l2 = 0; l2 < L; ++l2) {
                if (dp[l1][l2][p] < 0) continue;

                for (auto [l, w] : ps) {
                    if (!judge(l1, l2, l) || p + w > c) continue;

                    dp[l2][l][p + w] = std::max(dp[l2][l][p + w], dp[l1][l2][p] + l + 1);
                    ans = std::max(ans, dp[l2][l][p + w]);
                }
            }
        }
    }

    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0