結果

問題 No.484 収穫
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-02-13 13:42:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 3,000 ms
コード長 2,040 bytes
コンパイル時間 1,350 ms
コンパイル使用メモリ 158,636 KB
実行使用メモリ 66,784 KB
最終ジャッジ日時 2024-04-21 14:29:07
合計ジャッジ時間 3,421 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
66,596 KB
testcase_01 AC 29 ms
66,668 KB
testcase_02 AC 30 ms
66,724 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 30 ms
66,536 KB
testcase_05 AC 30 ms
66,544 KB
testcase_06 AC 29 ms
66,640 KB
testcase_07 AC 29 ms
66,628 KB
testcase_08 AC 30 ms
66,540 KB
testcase_09 AC 30 ms
66,784 KB
testcase_10 AC 30 ms
66,668 KB
testcase_11 AC 30 ms
66,720 KB
testcase_12 AC 73 ms
66,716 KB
testcase_13 AC 70 ms
66,568 KB
testcase_14 AC 71 ms
66,544 KB
testcase_15 AC 70 ms
66,772 KB
testcase_16 AC 70 ms
66,524 KB
testcase_17 AC 71 ms
66,668 KB
testcase_18 AC 71 ms
66,588 KB
testcase_19 AC 70 ms
66,592 KB
testcase_20 AC 71 ms
66,560 KB
testcase_21 AC 70 ms
66,612 KB
testcase_22 AC 70 ms
66,676 KB
testcase_23 AC 72 ms
66,580 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;
const ll INFF = 1e18;

//dp[l][r][isright] := 
//isright = 0のとき [l+1, r]が未収穫で、lにいるとき
//isright = 1のとき [l, r-1]が未収穫で、rにいるとき
ll dp[2010][2010][2];
int n;
ll a[2010];

signed main(void){
	cin >> n; rep(i, n) cin >> a[i];
	if(n == 1){
		printf("%lld\n", a[0]); return 0;
	}
	rep(i, 2010)rep(j, 2010)rep(k, 2) dp[i][j][k] = INFF;
	dp[0][n - 1][0] = a[0];
	dp[0][n - 1][1] = a[n - 1];
	for (int len = n - 1; len >= 0; --len){
		for (int i = 0; i + len <= n; ++i){
			rep(k, 2){
				//左端が l , 右端が r
				int l = i, r = i + len;
				if(dp[l][r][k] == INFF || l >= r) continue;
				ll time = dp[l][r][k];
				if(k == 0){//現在のセルが l の時 [l + 1, r]が未収穫
					//l->l+1
					if(time + 1 >= a[l + 1]) chmin(dp[l + 1][r][0], time + 1);
					else chmin(dp[l + 1][r][0], a[l + 1]);
					//l->r
					if(time + r - l >= a[r]) chmin(dp[l + 1][r][1], time + r - l);
					else chmin(dp[l + 1][r][1], a[r]);
				}else{//現在のセルが r の時 [l, r - 1]が未収穫
					//r->r-1
					if(time + 1 >= a[r - 1]) chmin(dp[l][r - 1][1], time + 1);
					else chmin(dp[l][r - 1][1], a[r - 1]);
					//r->l
					if(time + r - l >= a[l]) chmin(dp[l][r - 1][0], time + r - l);
					else chmin(dp[l][r - 1][0], a[l]);
				}
			}
		}
	}
	ll ans = INFF;
	rep(i, n)rep(j, 2){
		// printf("dp[%d][%d][%d] = %lld\n", i, i, j, dp[i][i][j]);
		chmin(ans, dp[i][i][j]);
	}
	printf("%lld\n", ans);
	return 0;
}
0