結果

問題 No.664 超能力者Aと株価予測
ユーザー snrnsidysnrnsidy
提出日時 2021-05-30 03:02:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,374 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 198,000 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 07:20:22
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std;

pair<long long int,long long int> dp[401][21][21];
int N, M, K;
int A[401];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M >> K;
    for (int i = 0; i <= N; i++)
    {
        cin >> A[i];
    }

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            for (int k = 0; k <= M; k++)
            {
                dp[i][j][k].first = -1;
                dp[i][j][k].second = -1;
            }
        }
    }

    dp[0][0][0].first = K;
    dp[0][0][0].second = 0;

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            for (int k = 0; k <= M; k++)
            {
                if (dp[i][j][k].first == -1)
                {
                    continue;
                }
                if (dp[i + 1][j][k] < dp[i][j][k])
                {
                    dp[i + 1][j][k] = dp[i][j][k];
                }
                if (j + 1 <= M)
                {
                    long long int X = (dp[i][j][k].first) / A[i];
                    long long int cost = A[i] * X;
                    long long int money = dp[i][j][k].first - cost;
                    if (dp[i + 1][j + 1][k].first < money)
                    {
                        dp[i + 1][j + 1][k] = make_pair(money, X);
                    }
                    else if (dp[i + 1][j + 1][k].first == money)
                    {
                        if (dp[i + 1][j + 1][k].second < X)
                        {
                            dp[i + 1][j + 1][k] = make_pair(money, X);
                        }
                    }
                }
                if (k + 1 <= j)
                {
                    long long int profit = A[i] * dp[i][j][k].second;
                    long long int X = 0;
                    long long int money = dp[i][j][k].first + profit;
                    if (dp[i + 1][j][k + 1].first < money)
                    {
                        dp[i + 1][j][k + 1] = make_pair(money, X);
                    }
                }
            }
        }
    }
    
    long long int res = 0;

    for (int i = 0; i <= M; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            res = max(res, dp[N + 1][i][j].first);
        }
    }
    cout << res << '\n';

    return 0;
}
0