結果

問題 No.324 落ちてた閉路グラフ
ユーザー しらっ亭しらっ亭
提出日時 2015-12-27 03:52:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 1,966 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 159,500 KB
実行使用メモリ 176,804 KB
最終ジャッジ日時 2024-04-27 16:05:59
合計ジャッジ時間 4,602 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
176,688 KB
testcase_01 AC 44 ms
176,464 KB
testcase_02 AC 45 ms
176,556 KB
testcase_03 AC 44 ms
176,556 KB
testcase_04 AC 82 ms
176,500 KB
testcase_05 AC 135 ms
176,752 KB
testcase_06 AC 74 ms
176,516 KB
testcase_07 AC 130 ms
176,532 KB
testcase_08 AC 77 ms
176,672 KB
testcase_09 AC 59 ms
176,652 KB
testcase_10 AC 76 ms
176,620 KB
testcase_11 AC 59 ms
176,624 KB
testcase_12 AC 46 ms
176,636 KB
testcase_13 AC 46 ms
176,632 KB
testcase_14 AC 52 ms
176,752 KB
testcase_15 AC 59 ms
176,512 KB
testcase_16 AC 44 ms
176,636 KB
testcase_17 AC 44 ms
176,528 KB
testcase_18 AC 45 ms
176,596 KB
testcase_19 AC 44 ms
176,636 KB
testcase_20 AC 45 ms
176,712 KB
testcase_21 AC 45 ms
176,428 KB
testcase_22 AC 45 ms
176,672 KB
testcase_23 AC 45 ms
176,560 KB
testcase_24 AC 46 ms
176,632 KB
testcase_25 AC 44 ms
176,484 KB
testcase_26 AC 43 ms
176,624 KB
testcase_27 AC 44 ms
176,592 KB
testcase_28 AC 44 ms
176,548 KB
testcase_29 AC 45 ms
176,700 KB
testcase_30 AC 44 ms
176,728 KB
testcase_31 AC 45 ms
176,580 KB
testcase_32 AC 134 ms
176,628 KB
testcase_33 AC 118 ms
176,640 KB
testcase_34 AC 77 ms
176,804 KB
testcase_35 AC 46 ms
176,600 KB
testcase_36 AC 53 ms
176,752 KB
testcase_37 AC 45 ms
176,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define MP(x,y) make_pair((x), (y))
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FILL_3F(a) memset(a,0x3f,sizeof(a))
#define FILL_F3(a) memset(a,0xf3,sizeof(a))
#define bitcount(b) __builtin_popcount(b)
#define GCD(a,b) (__gcd(a,b))
#define GCD3(a,b,c) (GCD(GCD(a,b), c))
#define LCM(a,b) (a/GCD(a,b)*b)
#define LCM3(a,b,c) LCM(LCM(a,b),c)
#define MOD 1000000007
template<class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
typedef long long ll;
// -------------------------------------

int N, M;
int W[3330];

int dp[3330][2][2][3330];  // pos, first, last, get

int main() {
  cin >> N >> M;
  REP(i, N) cin >> W[i];

  FILL_F3(dp);

  dp[0][0][0][0] = 0;

  REP(p, N + 1) REP(uf, 2) REP(up, 2) REP(m, M + 1) {
    if (m <= M) {
      int fb = (p == N - 1 && uf) ? W[p] : 0;
      int a = (up && p >= 1) ? W[p - 1] : 0;
      amax(dp[p + 1][uf || p == 0][1][m + 1], dp[p][uf][up][m] + a + fb);
    }
    amax(dp[p + 1][uf][0][m], dp[p][uf][up][m]);
  }

  /*
  REP(p, N + 1) REP(uf, 2) REP(up, 2) REP(m, M + 1) {
    _P("dp[%d][%d][%d][%d] = %d\n", p, uf, up, m, dp[p][uf][up][m]);
  }
  */

  int ans = -MOD;
  REP(uf, 2) REP(up, 2) amax(ans, dp[N][uf][up][M]);

  cout << ans << '\n';

  return 0;
}
0