結果

問題 No.484 収穫
ユーザー btkbtk
提出日時 2017-02-11 12:01:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 3,000 ms
コード長 1,389 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 173,436 KB
実行使用メモリ 66,048 KB
最終ジャッジ日時 2024-10-13 13:12:07
合計ジャッジ時間 3,442 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define DEBUG if(0)
using namespace std;

typedef long long LL;

struct cww{cww(){
    ios::sync_with_stdio(false);cin.tie(0);
    cout<<fixed;
    cout<<setprecision(10);
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define fi first
#define se second
#define pb push_back

template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<LL> V;
typedef vector<V> VV;
const LL INF=1e16;
int main(){
    int N;
    cin>>N;
    V A(N);cin>>A;
    VV L(N+2,V(N+2,INF));
    VV R(N+2,V(N+2,INF));
    L[2][N]=A[0];
    R[1][N-1]=A[N-1];
    for(int len=N-2;len>=0;len--){
        for(int l=0;l+len<N;l++){
            int r=l+len;
            DEBUG printf("L[%d][%d]=%lld\n",l,r,L[l+1][r+1]);
            DEBUG printf("R[%d][%d]=%lld\n",l,r,R[l+1][r+1]);
            chmin(L[l+2][r+1],max(L[l+1][r+1]+1,A[l]));
            chmin(R[l+1][r],max(L[l+1][r+1]+r-l+1,A[r]));
            chmin(L[l+2][r+1],max(R[l+1][r+1]+r-l+1,A[l]));
            chmin(R[l+1][r],max(R[l+1][r+1]+1,A[r]));
        }
    }
    LL res=INF;
    REP(i,N+1)chmin(res,L[i+1][i]);
    REP(i,N+1)chmin(res,R[i+1][i]);
    cout<<res<<endl;
    return 0;
}
0