結果

問題 No.324 落ちてた閉路グラフ
ユーザー te-shte-sh
提出日時 2017-06-27 17:10:17
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,160 bytes
コンパイル時間 3,068 ms
コンパイル使用メモリ 88,924 KB
実行使用メモリ 577,840 KB
最終ジャッジ日時 2023-09-03 14:50:43
合計ジャッジ時間 21,138 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1,311 ms
236,760 KB
testcase_05 MLE -
testcase_06 AC 930 ms
192,624 KB
testcase_07 MLE -
testcase_08 AC 995 ms
199,000 KB
testcase_09 AC 414 ms
92,152 KB
testcase_10 AC 995 ms
198,732 KB
testcase_11 AC 416 ms
92,500 KB
testcase_12 RE -
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 217 ms
52,168 KB
testcase_15 AC 419 ms
90,860 KB
testcase_16 RE -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 RE -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 RE -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 RE -
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 MLE -
testcase_33 AC 2,315 ms
474,020 KB
testcase_34 AC 999 ms
202,300 KB
testcase_35 AC 8 ms
4,376 KB
testcase_36 AC 252 ms
58,596 KB
testcase_37 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], m = rd[1];
  auto w = readln.split.to!(int[]);

  auto calc1()
  {
    auto dp = new int[][][](n+1, m+1, 2);
    foreach (i; 0..n+1)
      foreach (j; 0..m+1)
        foreach (k; 0..2)
          dp[i][j][k] = -10^^9;
    dp[1][0][0] = 0;

    foreach (i; 1..n)
      foreach (j; 0..m+1) {
        dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0], dp[i][j][1]);
        if (j < m)
          dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j][0], dp[i][j][1] + w[i-1]);
      }

    return max(dp[n][m][0], dp[n][m][1]);
  }

  auto calc2()
  {
    auto dp = new int[][][](n+1, m+1, 2);
    foreach (i; 0..n+1)
      foreach (j; 0..m+1)
        foreach (k; 0..2)
          dp[i][j][k] = -10^^9;
    dp[1][1][1] = 0;

    foreach (i; 1..n)
      foreach (j; 0..m+1) {
        dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0], dp[i][j][1]);
        if (j < m)
          dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j][0], dp[i][j][1] + w[i-1]);
      }

    return max(dp[n][m][0], dp[n][m][1] + w[n-1]);
  }

  writeln(max(calc1, calc2));
}
0