結果

問題 No.664 超能力者Aと株価予測
ユーザー nebukuro09nebukuro09
提出日時 2018-04-10 11:23:29
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 105,236 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 19:15:30
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto A = (N+1).iota.map!(_ => readln.chomp.to!int).array;

    auto dp = new int[][](N+1, M+1);
    dp[0][0] = K;

    foreach (i; 0..N) {
        if ((i == 0 || A[i] <= A[i-1]) && A[i] <= A[i+1]) {
            foreach (j; i+1..N+1) {
                if (A[j] >= A[j-1] && (j == N || A[j] >= A[j+1])) {
                    foreach (k; 0..M) {
                        int stock = dp[i][k] / A[i];
                        int rest = dp[i][k] % A[i];
                        int gain = stock * A[j];
                        dp[j][k+1] = max(dp[j][k+1], rest + gain);
                    }
                }
            }
        }
        foreach (k; 0..M+1) {
            dp[i+1][k] = max(dp[i+1][k], dp[i][k]);
        }
    }

    dp[N].reduce!max.writeln;
}
0