結果

問題 No.783 門松計画
ユーザー PachicobuePachicobue
提出日時 2019-01-11 22:40:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,506 bytes
コンパイル時間 2,937 ms
コンパイル使用メモリ 220,084 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-20 11:37:32
合計ジャッジ時間 4,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 301 ms
4,472 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
std::mt19937 mt{std::random_device{}()};
template <typename T>
std::vector<T> Vec(const std::size_t n, T v) { return std::vector<T>(n, v); }
template <class... Args>
auto Vec(const std::size_t n, Args... args) { return std::vector<decltype(Vec(args...))>(n, Vec(args...)); }
template <typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v)
{
    os << "[";
    for (const auto& p : v) { os << p << ","; }
    return (os << "]\n");
}
int main()
{
    int N, C;
    std::cin >> N >> C;
    std::vector<int> L(N), W(N);
    for (int i = 0; i < N; i++) { std::cin >> L[i]; }
    for (int i = 0; i < N; i++) { std::cin >> W[i]; }
    std::map<int, int> mp;
    for (int i = 0; i < N; i++) { mp[L[i]] = mp[L[i]] == 0 ? W[i] : std::min(mp[L[i]], W[i]); }
    int minimum = 0;
    for (const auto& p : mp) { minimum += p.second; }
    if (minimum > C) { return std::cout << 0 << std::endl, 0; }
    L.push_back(100000);
    auto dp = Vec(N + 1, N + 1, 51, 0);
    for (int i = 0; i < N; i++) { dp[N][i][W[i]] = L[i]; }
    for (int i = 0; i <= C; i++) {
        auto tmp = (i >= 2 ? dp : Vec(N + 1, N + 1, 51, 0));
        for (int pp = 0; pp <= N; pp++) {
            for (int p = 0; p < N; p++) {
                if (L[p] == L[pp]) { continue; }
                if (L[pp] > L[p]) {
                    for (int n = 0; n < N; n++) {
                        if (L[p] >= L[n] or L[pp] == L[n]) { continue; }
                        for (int c = 0; c + W[n] <= C; c++) { tmp[p][n][c + W[n]] = std::max(tmp[p][n][c + W[n]], dp[pp][p][c] + L[n]); }
                    }
                } else if (L[pp] < L[p]) {
                    for (int n = 0; n < N; n++) {
                        if (L[p] <= L[n] or L[pp] == L[n]) { continue; }
                        for (int c = 0; c + W[n] <= C; c++) { tmp[p][n][c + W[n]] = std::max(tmp[p][n][c + W[n]], dp[pp][p][c] + L[n]); }
                    }
                }
            }
        }
        dp = tmp;
        //        show(dp);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int c = 0; c <= C; c++) { ans = std::max(ans, dp[i][j][c]); }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
0