結果

問題 No.484 収穫
ユーザー pekempeypekempey
提出日時 2017-02-11 00:45:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 3,000 ms
コード長 1,010 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 72,684 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2024-04-21 14:24:50
合計ジャッジ時間 2,006 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
67,252 KB
testcase_01 AC 17 ms
67,200 KB
testcase_02 AC 17 ms
67,200 KB
testcase_03 AC 18 ms
67,312 KB
testcase_04 AC 17 ms
67,200 KB
testcase_05 AC 17 ms
67,200 KB
testcase_06 AC 16 ms
67,200 KB
testcase_07 AC 17 ms
67,328 KB
testcase_08 AC 18 ms
67,328 KB
testcase_09 AC 17 ms
67,328 KB
testcase_10 AC 19 ms
67,200 KB
testcase_11 AC 18 ms
67,200 KB
testcase_12 AC 33 ms
67,192 KB
testcase_13 AC 37 ms
67,328 KB
testcase_14 AC 35 ms
67,208 KB
testcase_15 AC 35 ms
67,200 KB
testcase_16 AC 35 ms
67,328 KB
testcase_17 AC 35 ms
67,328 KB
testcase_18 AC 34 ms
67,196 KB
testcase_19 AC 34 ms
67,200 KB
testcase_20 AC 35 ms
67,328 KB
testcase_21 AC 36 ms
67,312 KB
testcase_22 AC 35 ms
67,288 KB
testcase_23 AC 35 ms
67,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void chmin(long long &x, long long y) {
	x = min(x, y);
}

int main() {
	int n;
	cin >> n;
	vector<long long> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	static long long dp[2020][2020][2];
	const long long inf = 1e18;
	fill_n(**dp, 2020 * 2020 * 2, inf);

	dp[2][n][0] = a[1];
	dp[1][n - 1][1] = a[n];
	for (int d = n - 2; d >= 0; d--) {
		for (int l = 1; l + d <= n; l++) {
			int r = l + d;
			chmin(dp[l + 1][r][0], max<long long>(l - (l - 1), a[l] - dp[l][r][0]) + dp[l][r][0]);
			chmin(dp[l][r - 1][1], max<long long>(r - (l - 1), a[r] - dp[l][r][0]) + dp[l][r][0]);
			chmin(dp[l + 1][r][0], max<long long>((r + 1) - l, a[l] - dp[l][r][1]) + dp[l][r][1]);
			chmin(dp[l][r - 1][1], max<long long>((r + 1) - r, a[r] - dp[l][r][1]) + dp[l][r][1]);
		}
	}

	long long ans = 1e18;
	for (int i = 1; i <= n + 1; i++) {
		chmin(ans, dp[i][i - 1][0]);
		chmin(ans, dp[i][i - 1][1]);
	}
	cout << ans << endl;
}
0