結果

問題 No.324 落ちてた閉路グラフ
ユーザー nebukuro09nebukuro09
提出日時 2017-04-13 19:07:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 935 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 145,316 KB
実行使用メモリ 144,696 KB
最終ジャッジ日時 2023-09-25 16:27:18
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 98 ms
96,768 KB
testcase_05 AC 197 ms
144,624 KB
testcase_06 AC 83 ms
95,120 KB
testcase_07 AC 189 ms
142,748 KB
testcase_08 AC 88 ms
97,072 KB
testcase_09 AC 48 ms
81,048 KB
testcase_10 AC 88 ms
97,092 KB
testcase_11 AC 48 ms
81,336 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 16 ms
64,712 KB
testcase_14 AC 20 ms
40,924 KB
testcase_15 AC 33 ms
55,568 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 194 ms
144,696 KB
testcase_33 AC 165 ms
134,024 KB
testcase_34 AC 82 ms
90,896 KB
testcase_35 AC 3 ms
9,804 KB
testcase_36 AC 31 ms
69,792 KB
testcase_37 AC 2 ms
7,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)

const int INF = 1 << 29;
int N, M;
int W[3010];
int dp[3010][3010][2][2];

int main() {
    cin >> N >> M;
    REP(i, N) cin >> W[i];

    if (M == 0) {
      cout << 0 << endl;
      return 0;
    }

    REP(i, N+1) REP(j, M+1) REP(k, 2) REP(l, 2) dp[i][j][k][l] = -INF;
    dp[0][0][0][0] = 0;
    dp[0][1][1][1] = 0;

    REP2(i, 1, N) REP(j, M+1) REP(k, 2) REP(l, 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;
    REP(k, 2) REP(l, 2) ans = max(ans, dp[N-1][M][k][l]);
    cout << ans << endl;
}
0