結果
| 問題 |
No.484 収穫
|
| コンテスト | |
| ユーザー |
tossy
|
| 提出日時 | 2017-02-11 10:08:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 3,000 ms |
| コード長 | 1,420 bytes |
| コンパイル時間 | 1,441 ms |
| コンパイル使用メモリ | 168,872 KB |
| 実行使用メモリ | 34,944 KB |
| 最終ジャッジ日時 | 2024-10-13 13:11:59 |
| 合計ジャッジ時間 | 3,124 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#define INF 2147483600
#define long long long
int dp[2001][2001][2];
int main(){
int n;
cin>>n;
vector<int> vec(n);
rep(i,n) cin>>vec[i];
// dp[l][r][b] : [l,r]を未収穫で,b=0:左,b=1:右端を収穫可能な最短時刻
fill(dp[0][0], dp[2001][0], INF);
dp[0][n-1][0] = vec[0];
dp[0][n-1][1] = vec[n-1];
for(int d=n; d>1; d--){
for(int l=0; l+d-1<n; l++){
int r=l+d-1;
dp[l+1][r][0] = min(dp[l+1][r][0], max(vec[l+1], dp[l][r][0] + 1));
dp[l+1][r][1] = min(dp[l+1][r][1], max(vec[r], dp[l][r][0] + d-1));
dp[l][r-1][0] = min(dp[l][r-1][0], max(vec[l], dp[l][r][1] + d-1));
dp[l][r-1][1] = min(dp[l][r-1][1], max(vec[r-1], dp[l][r][1] + 1));
}
}
int ans = INF;
rep(i,n)rep(j,2) ans = min(ans, dp[i][i][j]);
cout<<ans<<endl;
return 0;
}
tossy