結果

問題 No.484 収穫
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-02-12 22:50:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,088 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 144,844 KB
実行使用メモリ 35,332 KB
最終ジャッジ日時 2023-08-28 14:56:07
合計ジャッジ時間 2,790 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,020 KB
testcase_01 AC 10 ms
35,116 KB
testcase_02 AC 11 ms
35,020 KB
testcase_03 WA -
testcase_04 AC 10 ms
35,032 KB
testcase_05 AC 11 ms
35,080 KB
testcase_06 AC 12 ms
35,040 KB
testcase_07 AC 12 ms
35,028 KB
testcase_08 AC 12 ms
35,232 KB
testcase_09 AC 12 ms
35,256 KB
testcase_10 AC 13 ms
35,032 KB
testcase_11 AC 11 ms
35,024 KB
testcase_12 AC 53 ms
35,084 KB
testcase_13 AC 56 ms
35,108 KB
testcase_14 AC 57 ms
35,044 KB
testcase_15 AC 57 ms
35,172 KB
testcase_16 AC 58 ms
35,028 KB
testcase_17 WA -
testcase_18 AC 55 ms
35,036 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 53 ms
35,044 KB
testcase_23 AC 56 ms
35,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

//dp[isright][l][r] := 閉区間[l,r]が未収穫で、現在のセル(isrigt=0のときl-1, r+1)にいるための最短時刻
int dp[2][2010][2010];
int n;
int a[2010];
int main(void){
	cin >> n; rep(i, n) cin >> a[i];
	rep(i, 2)rep(j, 2010)rep(k, 2010) dp[i][j][k] = INF;
	dp[0][1][n - 1] = a[0];
	dp[1][0][n - 2] = a[n - 1];
	rep(i, 2){
		for(int len = n - 1; len >= 1; --len)for(int j = 0; j + len < n; ++j){
			int k = j + len;
			if(dp[i][j][k] == INF) continue;
			int time = dp[i][j][k];
			// printf("time %d j:%d k:%d time:%d\n", i, j, k, time);
			if(i == 0){//左端(j - 1)にいるとき
				//j-1->j
				if(time + 1 >= a[j]) chmin(dp[0][j + 1][k], time + 1);
				else chmin(dp[0][j + 1][k], a[j]);
				// printf("1 %d\n", dp[0][j + 1][k]);
				// printf("2 %d\n", dp[0][j + 1][k]);
				//j-1->k
				if(time + k - j + 1 >= a[k]) chmin(dp[1][j][k - 1], time + k - j + 1);
				else chmin(dp[1][j][k - 1], a[k]);
				// printf("3 %d\n", dp[1][j][k - 1]);
				// printf("4 %d\n", dp[1][j][k - 1]);
			}else{//右端(k + 1)にいるとき
				//k+1->k
				if(time + 1 >= a[k]) chmin(dp[1][j][k - 1], time + 1);
				else chmin(dp[1][j][k - 1], a[k]);
				//k+1->j
				if(time + k - j + 1 >= a[j]) chmin(dp[0][j + 1][k], time + k - j + 1);
				else chmin(dp[0][j + 1][k], a[j]);
			}
		}
	}
	int ans = INF;
	rep(i, 2)rep(j, n){
		// printf("dp[%d][%d][%d] = %d\n", i, j, j, dp[i][j][j]);
		if(dp[i][j][j] + 1 >= a[j]) chmin(ans, dp[i][j][j] + 1);
		else chmin(ans, a[j]);
	}
	printf("%d\n", ans);
	return 0;
}
0