結果

問題 No.664 超能力者Aと株価予測
ユーザー MisterMister
提出日時 2020-08-18 10:39:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 4,000 ms
コード長 960 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 80,860 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 06:34:57
合計ジャッジ時間 1,377 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 6 ms
6,944 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

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

using lint = long long;

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

    std::vector<int> xs(n + 1);
    for (auto& x : xs) std::cin >> x;

    auto dp = vec(n + 1, vec(m + 1, 0LL));
    std::fill(dp[0].begin(), dp[0].end(), k);

    for (int r = 1; r <= n; ++r) {
        for (int i = 0; i <= m; ++i) {
            dp[r][i] = std::max(dp[r][i], dp[r - 1][i]);
        }

        for (int l = 0; l < r; ++l) {
            if (xs[r] <= xs[l]) continue;

            for (int i = 0; i < m; ++i) {
                lint gain = dp[l][i] / xs[l] * (xs[r] - xs[l]);
                dp[r][i + 1] = std::max(dp[r][i + 1], dp[l][i] + gain);
            }
        }
    }

    std::cout << dp[n][m] << "\n";
}

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

    solve();

    return 0;
}
0