結果

問題 No.324 落ちてた閉路グラフ
ユーザー motimoti
提出日時 2015-12-18 18:42:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 266 ms / 5,000 ms
コード長 1,439 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 103,520 KB
実行使用メモリ 141,568 KB
最終ジャッジ日時 2024-04-27 16:03:33
合計ジャッジ時間 3,809 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 122 ms
57,472 KB
testcase_05 AC 264 ms
141,568 KB
testcase_06 AC 98 ms
47,360 KB
testcase_07 AC 244 ms
129,536 KB
testcase_08 AC 111 ms
50,560 KB
testcase_09 AC 47 ms
22,784 KB
testcase_10 AC 104 ms
50,432 KB
testcase_11 AC 47 ms
22,784 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 21 ms
13,952 KB
testcase_15 AC 39 ms
23,168 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 252 ms
136,832 KB
testcase_33 AC 266 ms
114,304 KB
testcase_34 AC 108 ms
51,072 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 26 ms
13,952 KB
testcase_37 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, M; cin >> N >> M;
  int dp[N+1][M+1][2][2];
  rep(i, N+1) rep(j, M+1) rep(k, 2) rep(l, 2) dp[i][j][k][l] = -inf;
  int w[N]; rep(i, N) { cin >> w[i]; }
  dp[0][M][0][0] = 0;
  rep(i, N) rep(used, M+1) rep(prevused, 2) rep(firstused, 2) {
    auto && curr = dp[i][used][prevused][firstused];
    if(curr == -inf) { continue; }
    if(used) {
      int ncost = curr + (i > 0 && prevused ? w[i-1] : 0);
      if(i == N-1 && firstused) ncost += w[N-1];
      maximize(dp[i+1][used-1][1][firstused || i == 0], ncost);
    }
    maximize(dp[i+1][used][0][firstused], curr);
  }

  int max = -inf;
  rep(i, 2) rep(j, 2) {
    maximize(max, dp[N][0][i][j]);
  }

  cout << max << endl;

  return 0;
}
0