結果

問題 No.484 収穫
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-02-12 12:48:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 3,000 ms
コード長 1,038 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 164,096 KB
実行使用メモリ 66,952 KB
最終ジャッジ日時 2024-04-21 14:28:47
合計ジャッジ時間 3,309 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 5 ms
10,060 KB
testcase_10 AC 5 ms
10,064 KB
testcase_11 AC 5 ms
10,128 KB
testcase_12 AC 62 ms
66,944 KB
testcase_13 AC 61 ms
66,932 KB
testcase_14 AC 60 ms
66,828 KB
testcase_15 AC 60 ms
66,952 KB
testcase_16 AC 61 ms
66,896 KB
testcase_17 AC 61 ms
66,912 KB
testcase_18 AC 61 ms
66,840 KB
testcase_19 AC 61 ms
66,908 KB
testcase_20 AC 60 ms
66,868 KB
testcase_21 AC 60 ms
66,880 KB
testcase_22 AC 60 ms
66,900 KB
testcase_23 AC 61 ms
66,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




typedef long long ll;
#define INF 1LL<<60
int N;
int A[2020];
//-----------------------------------------------------------------
ll dp[2020][2020][2];
ll dfs(int l, int r, int dir) {
	if (0 <= dp[l][r][dir]) return dp[l][r][dir];

	if (l == 0 && r == N - 1) {
		if (dir == 0) return A[0];
		else return A[N - 1];
	}

	ll ret = INF;
	if (dir == 0) {
		if (0 < l) ret = min(ret, dfs(l - 1, r, 0) + 1);
		if (r < N - 1) ret = min(ret, dfs(l, r + 1, 1) + (r - l + 1));
		ret = max(ret, (ll)A[l]);
	} else {
		if (0 < l) ret = min(ret, dfs(l - 1, r, 0) + (r - l + 1));
		if (r < N - 1) ret = min(ret, dfs(l, r + 1, 1) + 1);
		ret = max(ret, (ll)A[r]);
	}
	return dp[l][r][dir] = ret;
}
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &A[i]);

	ll ans = INF;
	rep(i, 0, N) rep(j, 0, N) rep(k, 0, 2) dp[i][j][k] = -1;
	rep(i, 0, N) ans = min(ans, dfs(i, i, 0));
	cout << ans << endl;
}
0