結果

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

テストケース

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

ソースコード

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 + j - k - 1 >= a[j]) chmin(dp[0][j + 1][k], time + j - k - 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