結果

問題 No.484 収穫
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-02-12 12:48:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,022 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 166,156 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 14:51:30
合計ジャッジ時間 7,066 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

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 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