結果

問題 No.37 遊園地のアトラクション
コンテスト
ユーザー himueu
提出日時 2026-10-21 23:04:59
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 5,000 ms
+ 284µs
コード長 983 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,998 ms
コンパイル使用メモリ 183,980 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-21 23:05:08
合計ジャッジ時間 3,953 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    using namespace std;
    int t, n;
    cin >> t >> n;
    vector<int> C(n), V(n);
    for (auto &e : C) { cin >> e; }
    for (auto &e : V) { cin >> e; }
    vector<pair<int, int>> attractions;
    for (int i = 0; i < n; i++) {
        while (V[i] > 0) {
            attractions.emplace_back(C[i], V[i]);
            V[i] /= 2;
        }
    }

    n = attractions.size();
    vector dp(n + 1, vector<int>(t + 1, -1));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        auto [c, v] = attractions[i];
        for (int j = 0; j < t + 1; j++) {
            if (dp[i][j] == -1) { continue; }
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + c <= t) {
                dp[i + 1][j + c] = max(dp[i + 1][j + c], dp[i][j] + v);
            }
        }
    }
    int ans = 0;
    for (int j = 0; j < t + 1; j++) {
        ans = max(ans, dp[n][j]);
    }
    cout << ans << endl;
}
0