結果

問題 No.324 落ちてた閉路グラフ
ユーザー motimoti
提出日時 2015-12-18 18:40:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 1,438 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 100,192 KB
実行使用メモリ 141,688 KB
最終ジャッジ日時 2023-08-09 21:40:22
合計ジャッジ時間 3,564 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 91 ms
57,568 KB
testcase_05 AC 255 ms
141,688 KB
testcase_06 AC 75 ms
47,548 KB
testcase_07 AC 219 ms
129,580 KB
testcase_08 AC 80 ms
50,532 KB
testcase_09 AC 35 ms
22,872 KB
testcase_10 AC 80 ms
50,524 KB
testcase_11 AC 35 ms
22,856 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 20 ms
13,888 KB
testcase_15 AC 36 ms
23,320 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 230 ms
137,204 KB
testcase_33 AC 187 ms
114,432 KB
testcase_34 AC 80 ms
51,112 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 20 ms
13,992 KB
testcase_37 AC 1 ms
4,384 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