結果

問題 No.324 落ちてた閉路グラフ
ユーザー cielciel
提出日時 2018-07-09 01:18:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 2,233 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 167,600 KB
実行使用メモリ 75,144 KB
最終ジャッジ日時 2023-09-22 08:25:20
合計ジャッジ時間 3,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 41 ms
74,276 KB
testcase_05 AC 77 ms
75,044 KB
testcase_06 AC 36 ms
73,956 KB
testcase_07 AC 77 ms
75,080 KB
testcase_08 AC 38 ms
73,988 KB
testcase_09 AC 25 ms
73,808 KB
testcase_10 AC 37 ms
73,992 KB
testcase_11 AC 25 ms
73,620 KB
testcase_12 AC 15 ms
69,352 KB
testcase_13 AC 10 ms
42,568 KB
testcase_14 AC 10 ms
22,912 KB
testcase_15 AC 16 ms
31,256 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 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,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 78 ms
74,972 KB
testcase_33 AC 69 ms
75,144 KB
testcase_34 AC 36 ms
61,984 KB
testcase_35 AC 2 ms
6,044 KB
testcase_36 AC 17 ms
51,268 KB
testcase_37 AC 3 ms
5,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, M, W[3030];
//---------------------------------------------------------------------------------------------------
int dp[3030][3030][2];
int f(int flag) {
    rep(i, 0, N + 1) rep(j, 0, M + 1) rep(k, 0, 2) dp[i][j][k] = -inf;

    if (flag) dp[0][1][1] = 0;
    else dp[0][0][0] = 0;

    rep(i, 1, N) rep(j, 0, M + 1) {
        // dp[i][j][0] 取らない
        chmax(dp[i][j][0], dp[i - 1][j][0]);
        chmax(dp[i][j][0], dp[i - 1][j][1]);

        // dp[i][j][1] 取る
        if (j>0) chmax(dp[i][j][1], dp[i - 1][j - 1][0]);
        if (j>0) chmax(dp[i][j][1], dp[i - 1][j - 1][1] + W[i]);
    }

    int res = dp[N - 1][M][0];
    if (flag) chmax(res, dp[N - 1][M][1] + W[0]);
    else chmax(res, dp[N - 1][M][1]);
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, N) cin >> W[i];

    int ans = -inf;
    chmax(ans, f(0));
    chmax(ans, f(1));
    cout << ans << endl;
}
0