結果

問題 No.664 超能力者Aと株価予測
ユーザー snrnsidysnrnsidy
提出日時 2021-05-30 03:18:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 4,000 ms
コード長 1,894 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 195,676 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 07:31:30
合計ジャッジ時間 3,115 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std;

long long int dp[2][21][2][301];
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];
    }

    memset(dp, -1, sizeof(dp));
    dp[1][0][0][0] = K;

    for (int i = 0; i <= N; i++)
    {
        memcpy(dp[0], dp[1], sizeof(dp[1]));
        memset(dp[1], -1, sizeof(dp[1]));
        for (int a = 0; a <= M; a++)
        {
            for (int b = 0; b < 2; b++)
            {
                for (int c = 0; c <= 300; c++)
                {
                    if (dp[0][a][b][c] == -1)
                    {
                        continue;
                    }
                    dp[1][a][b][c] = max(dp[1][a][b][c], dp[0][a][b][c]);
                    if (b == 0)
                    {
                        if (a + 1 <= M)
                        {
                            dp[1][a + 1][1][A[i]] = max(dp[1][a + 1][1][A[i]], dp[0][a][b][c]);
                        }
                    }
                    if (c != 0 && b == 1)
                    {
                        long long int num = (dp[0][a][b][c] / c);
                        long long int money = dp[0][a][b][c] % c + (num * A[i]);
                        //cout << a << ' ' << b << ' ' << c << ' ' << i << ' ' << num << ' ' << money << '\n';
                        dp[1][a][0][0] = max(dp[1][a][0][0], money);
                    }
                }
            }
        }
    }

    //cout << dp[1][1][1][100] << ' ' << dp[1][1][0][0] << '\n';
    long long int res = 0;

    for (int i = 0; i <= M; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            for (int k = 0; k <= 300; k++)
            {
                res = max(res, dp[1][i][j][k]);
            }
        }
    }

    cout << res << '\n';

    return 0;
}
0