結果

問題 No.484 収穫
ユーザー tansunogontansunogon
提出日時 2017-05-05 19:05:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 68,976 KB
実行使用メモリ 34,932 KB
最終ジャッジ日時 2023-10-12 09:49:10
合計ジャッジ時間 2,055 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,608 KB
testcase_01 AC 11 ms
34,624 KB
testcase_02 AC 11 ms
34,668 KB
testcase_03 AC 10 ms
34,628 KB
testcase_04 AC 11 ms
34,672 KB
testcase_05 AC 11 ms
34,688 KB
testcase_06 WA -
testcase_07 AC 11 ms
34,616 KB
testcase_08 WA -
testcase_09 AC 11 ms
34,692 KB
testcase_10 AC 11 ms
34,740 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 27 ms
34,628 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 1e9;

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 >= 0; --j)
		{
			if (i > j)
			{
				continue;
			}

			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][0], 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