結果

問題 No.484 収穫
ユーザー tansunogontansunogon
提出日時 2017-05-05 19:19:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 3,000 ms
コード長 980 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 68,452 KB
実行使用メモリ 34,856 KB
最終ジャッジ日時 2023-08-03 16:24:50
合計ジャッジ時間 2,159 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,616 KB
testcase_01 AC 10 ms
34,856 KB
testcase_02 AC 11 ms
34,624 KB
testcase_03 AC 10 ms
34,756 KB
testcase_04 AC 10 ms
34,672 KB
testcase_05 AC 10 ms
34,616 KB
testcase_06 AC 10 ms
34,628 KB
testcase_07 AC 11 ms
34,756 KB
testcase_08 AC 11 ms
34,624 KB
testcase_09 AC 11 ms
34,688 KB
testcase_10 AC 11 ms
34,696 KB
testcase_11 AC 11 ms
34,684 KB
testcase_12 AC 25 ms
34,648 KB
testcase_13 AC 25 ms
34,828 KB
testcase_14 AC 24 ms
34,684 KB
testcase_15 AC 25 ms
34,632 KB
testcase_16 AC 24 ms
34,624 KB
testcase_17 AC 25 ms
34,620 KB
testcase_18 AC 24 ms
34,696 KB
testcase_19 AC 25 ms
34,628 KB
testcase_20 AC 24 ms
34,832 KB
testcase_21 AC 24 ms
34,688 KB
testcase_22 AC 24 ms
34,852 KB
testcase_23 AC 25 ms
34,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::cin.sync_with_stdio(false);
	}
} iostream_init;

#include <cstring>
#include <algorithm>

int N;
int A[2000];

int dp[2000][2000][2];
const int INF = 2e9;

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	memset(dp, 0x3f, sizeof dp);
	dp[0][N - 1][0] = A[0];
	dp[0][N - 1][1] = A[N - 1];

	for (int i = 0; i < N; ++i)
	{
		for (int j = N - 1; j >= i; --j)
		{
			if (i - 1 >= 0)
			{
				dp[i][j][0] = min(dp[i][j][0], max(A[i], dp[i - 1][j][0] + 1));
				dp[i][j][1] = min(dp[i][j][1], max(A[j], dp[i - 1][j][0] + j - (i - 1)));
			}
			if (j + 1 < N)
			{
				dp[i][j][0] = min(dp[i][j][0], max(A[i], dp[i][j + 1][1] + (j + 1) - i));
				dp[i][j][1] = min(dp[i][j][1], max(A[j], dp[i][j + 1][1] + 1));
			}
		}
	}

	int ans = INF;
	for (int i = 0; i < N; ++i)
	{
		ans = min(ans, dp[i][i][0]);
	}

	cout << ans << endl;
}
0