結果

問題 No.324 落ちてた閉路グラフ
ユーザー latte0119latte0119
提出日時 2016-05-24 18:14:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 1,225 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 69,764 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-27 16:10:30
合計ジャッジ時間 1,848 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<sstream>
#include<bitset>
#include<numeric>
#include<climits>
using namespace std;

typedef long long ll;

template<typename A,typename B>inline void chmin(A &a, B b) { if (a > b)a = b; }
template<typename A,typename B>inline void chmax(A &a, B b) { if (a < b)a = b; }
const int INF = 1001001001;

int n, m;
int w[3000];

int dp[2][3010][2];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> w[i];
	
	int ans = -INF;

	for (int t = 0; t < 2; t++) {
		for (int i = 0; i < 2; i++)for (int j = 0; j < 3010; j++)for (int k = 0; k < 2; k++)dp[i][j][k] = -INF;
		//fill_n(**dp, 2 * 3010 * 2, -INF);
		dp[1][t][t] = 0;
		for (int i = 1; i < n; i++) {
			for (int j = 0; j <= m; j++) {
				for (int k = 0; k < 2; k++) {
					if (dp[i & 1][j][k] == -INF)continue;
					chmax(dp[(i + 1) & 1][j + 1][1], dp[i & 1][j][k] + k*w[i - 1]);
					chmax(dp[(i + 1) & 1][j][0], dp[i & 1][j][k]);
					dp[i & 1][j][k] = -INF;
				}
			}
		}
		for (int i = 0; i < 2; i++)chmax(ans, dp[n & 1][m][i] + (i&t)*w[n - 1]);
	}

	cout << ans << endl;
	return 0;
}
0