結果

問題 No.484 収穫
ユーザー Grun1396Grun1396
提出日時 2017-04-15 12:29:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 3,000 ms
コード長 1,296 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 78,860 KB
実行使用メモリ 50,432 KB
最終ジャッジ日時 2024-04-21 14:30:48
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 97 ms
50,432 KB
testcase_13 AC 98 ms
50,176 KB
testcase_14 AC 96 ms
50,304 KB
testcase_15 AC 98 ms
50,304 KB
testcase_16 AC 95 ms
50,304 KB
testcase_17 AC 97 ms
50,432 KB
testcase_18 AC 94 ms
50,304 KB
testcase_19 AC 96 ms
50,304 KB
testcase_20 AC 94 ms
50,176 KB
testcase_21 AC 98 ms
50,304 KB
testcase_22 AC 95 ms
50,304 KB
testcase_23 AC 98 ms
50,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0