結果

問題 No.324 落ちてた閉路グラフ
ユーザー nebukuro09nebukuro09
提出日時 2017-04-13 17:50:17
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,438 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 102,696 KB
実行使用メモリ 817,880 KB
最終ジャッジ日時 2023-09-03 12:47:38
合計ジャッジ時間 10,244 ms
ジャッジサーバーID
(参考情報)
judge11 / 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,380 KB
testcase_04 AC 1,385 ms
343,548 KB
testcase_05 MLE -
testcase_06 AC 1,208 ms
281,268 KB
testcase_07 MLE -
testcase_08 AC 1,219 ms
297,172 KB
testcase_09 AC 509 ms
130,712 KB
testcase_10 AC 1,217 ms
296,436 KB
testcase_11 AC 517 ms
130,392 KB
testcase_12 AC 3 ms
4,824 KB
testcase_13 AC 3 ms
4,476 KB
testcase_14 AC 250 ms
71,492 KB
testcase_15 AC 507 ms
130,676 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,356 KB
testcase_18 AC 1 ms
4,356 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,356 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,356 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 MLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

immutable int INF = 1 << 29;
void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto W = readln.split.map!(to!int).array;

    if (M == 0) {
        writeln(0);
        return;
    }

    // dp[i][j][k][l]  頂点iまででj個の辺をとったときの最大値
    // k: 直前の頂点を取ったか?
    // l: 頂点0を取ったか?
    auto dp = new int[][][][](N+1, M+1, 2, 2);
    foreach (i; 0..N+1) foreach (j; 0..M+1) foreach(k; 0..2) fill(dp[i][j][k], -INF);
    dp[0][0][0][0] = 0;
    dp[0][1][1][1] = 0;

    foreach (i; 1..N) {
        foreach (j; 0..M+1) {
            foreach (k; 0..2) {
                foreach (l; 0..2) {
                    if (dp[i-1][j][k][l] == -INF) continue;
                    int take = 0;
                    if (k) take += W[i-1];
                    if (i == N-1 && l) take += W[N-1];

                    if (j < M) dp[i][j+1][1][l] =
                                   max(dp[i][j+1][1][l], dp[i-1][j][k][l] + take);
                    dp[i][j][0][l] = max(dp[i][j][0][l], dp[i-1][j][k][l]);
                }
            }
        }
    }


    int ans = -INF;
    foreach (k; 0..2) foreach (l; 0..2) ans = max(ans, dp[N-1][M][k][l]);
    ans.writeln;
}
0