結果

問題 No.324 落ちてた閉路グラフ
ユーザー sugim48sugim48
提出日時 2015-12-17 00:11:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,783 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 80,648 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 11:39:06
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int INF = INT_MAX / 2;

int main() {
	int n, m; cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int ma = -INF;
	{
		vector<int> dp0(m + 1, -INF), dp1(m + 1, -INF);
		dp0[0] = 0;
		for (int i = 1; i < n; i++) {
			vector<int> _dp0(m + 1, -INF), _dp1(m + 1, -INF);
			for (int j = 0; j <= m; j++) {
				_dp0[j] = max(_dp0[j], dp0[j]);
				_dp0[j] = max(_dp0[j], dp1[j]);
				if (j + 1 <= m) {
					_dp1[j + 1] = max(_dp1[j + 1], dp0[j]);
					_dp1[j + 1] = max(_dp1[j + 1], dp1[j] + a[i - 1]);
				}
			}
			dp0 = _dp0; dp1 = _dp1;
		}
		ma = max(ma, dp0[m]);
		ma = max(ma, dp1[m]);
	}
	{
		vector<int> dp0(m + 1, -INF), dp1(m + 1, -INF);
		dp1[1] = 1;
		for (int i = 1; i < n; i++) {
			vector<int> _dp0(m + 1, -INF), _dp1(m + 1, -INF);
			for (int j = 0; j <= m; j++) {
				_dp0[j] = max(_dp0[j], dp0[j]);
				_dp0[j] = max(_dp0[j], dp1[j]);
				if (j + 1 <= m) {
					_dp1[j + 1] = max(_dp1[j + 1], dp0[j]);
					_dp1[j + 1] = max(_dp1[j + 1], dp1[j] + a[i - 1]);
				}
			}
			dp0 = _dp0; dp1 = _dp1;
		}
		ma = max(ma, dp0[m]);
		ma = max(ma, dp1[m] + a[n - 1]);
	}
	cout << ma << endl;
}
0