結果

問題 No.324 落ちてた閉路グラフ
ユーザー pekempeypekempey
提出日時 2015-12-17 00:17:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 1,195 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 145,892 KB
実行使用メモリ 147,192 KB
最終ジャッジ日時 2023-08-09 21:26:38
合計ジャッジ時間 4,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
146,944 KB
testcase_01 AC 49 ms
146,936 KB
testcase_02 AC 50 ms
146,876 KB
testcase_03 AC 49 ms
147,140 KB
testcase_04 AC 73 ms
147,052 KB
testcase_05 AC 108 ms
146,992 KB
testcase_06 AC 71 ms
146,880 KB
testcase_07 AC 106 ms
147,004 KB
testcase_08 AC 71 ms
147,004 KB
testcase_09 AC 59 ms
146,900 KB
testcase_10 AC 70 ms
147,136 KB
testcase_11 AC 59 ms
146,916 KB
testcase_12 AC 50 ms
146,880 KB
testcase_13 AC 50 ms
146,996 KB
testcase_14 AC 54 ms
146,852 KB
testcase_15 AC 59 ms
146,952 KB
testcase_16 AC 49 ms
146,912 KB
testcase_17 AC 50 ms
147,060 KB
testcase_18 AC 50 ms
146,972 KB
testcase_19 AC 50 ms
147,116 KB
testcase_20 AC 51 ms
146,976 KB
testcase_21 AC 50 ms
146,956 KB
testcase_22 AC 50 ms
146,924 KB
testcase_23 AC 49 ms
146,928 KB
testcase_24 AC 49 ms
147,180 KB
testcase_25 AC 48 ms
147,044 KB
testcase_26 AC 49 ms
146,848 KB
testcase_27 AC 49 ms
146,844 KB
testcase_28 AC 51 ms
146,848 KB
testcase_29 AC 50 ms
146,932 KB
testcase_30 AC 50 ms
147,044 KB
testcase_31 AC 49 ms
147,040 KB
testcase_32 AC 109 ms
147,152 KB
testcase_33 AC 99 ms
147,192 KB
testcase_34 AC 72 ms
146,872 KB
testcase_35 AC 49 ms
147,172 KB
testcase_36 AC 54 ms
146,872 KB
testcase_37 AC 50 ms
147,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using namespace std;
typedef long long ll;

const int inf = 1e9;
int dp[3030][3030][2][2]; // i, num, take prev, take 0

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> w(n);
	rep (i, n) scanf("%d", &w[i]);

	rep (i, 3030) rep (j, 3030) rep (k, 2) rep (l, 2) dp[i][j][k][l] = -inf;
	dp[0][0][0][0] = 0;
	dp[0][1][1][1] = 0;
	rep (i, 1, n) rep (j, m + 1) rep (k, 2) rep (l, 2) {
		chmax(dp[i][j][0][l], dp[i - 1][j][k][l]);
		chmax(dp[i][j + 1][1][l], dp[i - 1][j][k][l] + w[i] * k);
	}
	int ans = -inf;
	rep (k, 2) rep (l, 2) {
		chmax(ans, dp[n - 1][m][k][l] + k * l * w[0]);
	}
	cout << ans << endl;
	return 0;
}
0