結果

問題 No.1117 数列分割
ユーザー nebukuro09nebukuro09
提出日時 2020-07-17 22:20:07
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,358 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 117,724 KB
実行使用メモリ 219,256 KB
最終ジャッジ日時 2023-09-04 08:32:39
合計ジャッジ時間 7,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 38 ms
27,216 KB
testcase_04 AC 35 ms
28,036 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 33 ms
28,016 KB
testcase_09 AC 14 ms
14,492 KB
testcase_10 AC 35 ms
31,300 KB
testcase_11 AC 135 ms
101,568 KB
testcase_12 AC 136 ms
94,508 KB
testcase_13 AC 167 ms
95,072 KB
testcase_14 AC 192 ms
112,760 KB
testcase_15 AC 242 ms
135,984 KB
testcase_16 AC 252 ms
170,540 KB
testcase_17 AC 60 ms
90,456 KB
testcase_18 AC 426 ms
219,256 KB
testcase_19 AC 422 ms
219,200 KB
testcase_20 AC 215 ms
147,108 KB
testcase_21 AC 428 ms
219,052 KB
testcase_22 AC 409 ms
219,188 KB
testcase_23 AC 409 ms
219,100 KB
testcase_24 AC 403 ms
219,188 KB
testcase_25 AC 409 ms
219,220 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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, core.stdc.stdlib, std.datetime;

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

    auto S = new long[][](N, N);
    foreach (i; 0..N) {
        long tmp = 0;
        foreach (j; i..N) {
            tmp += A[j];
            S[i][j] = abs(tmp);
        }
    }

    long calc(bool init_pos) {
        auto dp = new long[][](N+1, K+1);
        foreach (i; 0..N+1) dp[i][] = -(1L << 59);
        dp[0][0] = 0;
        foreach (i; 0..N) {
            bool positive = init_pos;
            foreach (j; 0..K) {
                if (positive) {
                    dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A[i]);
                    dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i]);
                } else {
                    dp[i+1][j] = max(dp[i+1][j], dp[i][j] - A[i]);
                    dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] - A[i]);
                }
                positive = !positive;
            }
        }
        long ans = 0;
        foreach (j; 0..K+1) ans = max(ans, dp[N][j]);
        return ans;
    }

    writeln(max(calc(true), calc(false)));
}

0