結果

問題 No.324 落ちてた閉路グラフ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-04-28 08:20:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 2,229 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 165,392 KB
実行使用メモリ 75,228 KB
最終ジャッジ日時 2023-09-21 10:31:05
合計ジャッジ時間 3,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 39 ms
74,140 KB
testcase_05 AC 75 ms
75,052 KB
testcase_06 AC 36 ms
74,220 KB
testcase_07 AC 73 ms
75,228 KB
testcase_08 AC 36 ms
74,156 KB
testcase_09 AC 23 ms
73,640 KB
testcase_10 AC 35 ms
74,152 KB
testcase_11 AC 23 ms
73,876 KB
testcase_12 AC 14 ms
69,308 KB
testcase_13 AC 9 ms
42,620 KB
testcase_14 AC 9 ms
22,768 KB
testcase_15 AC 16 ms
31,104 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 79 ms
75,060 KB
testcase_33 AC 67 ms
75,004 KB
testcase_34 AC 35 ms
61,964 KB
testcase_35 AC 2 ms
5,900 KB
testcase_36 AC 15 ms
51,096 KB
testcase_37 AC 2 ms
5,780 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) chmax(dp[i][j][1], dp[i - 1][j - 1][0]);
        if (j) 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