結果

問題 No.324 落ちてた閉路グラフ
ユーザー pekempeypekempey
提出日時 2015-12-17 16:21:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 1,280 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 162,496 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 16:02:55
合計ジャッジ時間 2,897 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 54 ms
6,940 KB
testcase_05 AC 101 ms
6,940 KB
testcase_06 AC 51 ms
6,940 KB
testcase_07 AC 89 ms
6,944 KB
testcase_08 AC 49 ms
6,944 KB
testcase_09 AC 37 ms
6,944 KB
testcase_10 AC 49 ms
6,940 KB
testcase_11 AC 37 ms
6,940 KB
testcase_12 AC 27 ms
6,940 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 14 ms
6,940 KB
testcase_15 AC 21 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 90 ms
6,940 KB
testcase_33 AC 78 ms
6,944 KB
testcase_34 AC 45 ms
6,940 KB
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 26 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         rep (i, n) scanf("%d", &w[i]);
      |                    ~~~~~^~~~~~~~~~~~~

ソースコード

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 dp0[3030][2][2]; // num, take prev, take 0
int dp1[3030][2][2]; // 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 (j, 3030) rep (k, 2) rep (l, 2) dp0[j][k][l] = -inf;
	dp0[0][0][0] = 0;
	dp0[1][1][1] = 0;
	rep (i, 1, n) {
		rep (j, m + 1) rep (k, 2) rep (l, 2) dp1[j][k][l] = -inf;
		rep (j, m + 1) rep (k, 2) rep (l, 2) {
			chmax(dp1[j][0][l], dp0[j][k][l]);
			chmax(dp1[j + 1][1][l], dp0[j][k][l] + w[i] * k);
		}
		swap(dp0, dp1);
	}
	int ans = -inf;
	rep (k, 2) rep (l, 2) {
		chmax(ans, dp0[m][k][l] + k * l * w[0]);
	}
	cout << ans << endl;
	return 0;
}
0