結果
| 問題 |
No.484 収穫
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-15 12:29:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 3,000 ms |
| コード長 | 1,296 bytes |
| コンパイル時間 | 753 ms |
| コンパイル使用メモリ | 77,968 KB |
| 実行使用メモリ | 50,432 KB |
| 最終ジャッジ日時 | 2024-10-13 13:16:13 |
| 合計ジャッジ時間 | 2,690 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; (i) < int(n); ++(i))
#define rep_rev(i,n) for(int i = (n)-1;(i) >= 0; --(i))
using namespace std;
template<typename X,typename T> auto vectors(X x, T a){return vector<T>(x,a);}
template<typename X,typename Y, typename Z,typename... Zs> auto vectors(X x,Y y,Z z,Zs... zs){
auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont);
}
const int inf = 1.01e9;
int main(){
int n; cin >> n;
vector<int> a(n); rep(i,n) cin >> a[i];
auto dp = vectors(2,n+1,n+1,inf);
dp[false][1][n] = a[0];
dp[true][0][n-1] = a[n-1];
rep_rev(len,n+1){
rep(l,n - len + 1){
int r = l + len;
if(0 <= l-1){
dp[false][l][r] = min(dp[false][l][r],max(dp[false][l-1][r]+1, a[l-1]));
dp[false][l][r] = min(dp[false][l][r],max(dp[true ][l-1][r]+r-l+1,a[l-1]));
}
if(r+1 < n+1){
dp[true][l][r] = min(dp[true][l][r],max(dp[false][l][r+1]+r-l+1,a[r]));
dp[true][l][r] = min(dp[true][l][r],max(dp[true ][l][r+1]+1, a[r]));
}
}
}
int ans = inf;
rep(p,2) rep(l,n+1) ans = min(ans,dp[p][l][l]);
cout << ans << endl;
return 0;
}