結果

問題 No.324 落ちてた閉路グラフ
ユーザー motimoti
提出日時 2015-12-18 18:38:10
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,470 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 109,588 KB
実行使用メモリ 814,896 KB
最終ジャッジ日時 2023-10-14 14:00:52
合計ジャッジ時間 4,509 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
  vector<vector<vector<vector<int>>>> dp(N+1, vector<vector<vector<int>>>(M+1, vector<vector<int>>(2, vector<int>(2, -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