結果

問題 No.484 収穫
ユーザー t9unkubj
提出日時 2025-01-14 19:56:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,070 ms / 3,000 ms
コード長 1,945 bytes
コンパイル時間 4,555 ms
コンパイル使用メモリ 297,660 KB
実行使用メモリ 66,308 KB
最終ジャッジ日時 2025-01-14 19:56:58
合計ジャッジ時間 21,171 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef t9unkubj
#include"debug.cpp"
//#include"template_no_debug.h"
#else 
#define dbg(...) 199958
#endif

#undef _GLIBCXX_DEBUG
#pragma GCC optimize("O3")
using namespace std;
#include<bits/stdc++.h>
using ll=long long;
using ull=unsigned long long;
template<class T>using vc=vector<T>;
template<class T>using vvc=vc<vc<T>>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)
#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)
#define drep(i,n) for(ll i=((n)-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T,class F>
bool chmin(T &x, F y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template<class T, class F>
bool chmax(T &x, F y){
    if(x<y){
        x=y;
        return true;
    }
    return false;
}
double pass_time=0;
constexpr int N=2001;
ll dp[N][N][2];
void solve(){
    int n;
    cin>>n;
    vc<ll>a(n);
    rep(i,n)cin>>a[i];
    ll wa=*max_element(all(a))-1,ac=2e9;
    while(ac-wa>1){
        ll wj=ac+wa>>1;
        rep(i,N)rep(j,N)rep(k,2)dp[i][j][k]=-2e18;
        rep(i,n){
            dp[i][i+1][0]=wj;
            dp[i][i+1][1]=wj;
        }
        for(int w=2;w<=n;w++){
            rep(l,n-w+1){
                int r=l+w;
                //[l,r)
                if(dp[l][r-1][1]-1>=a[r-1]){
                    chmax(dp[l][r][1],dp[l][r-1][1]-1);
                }
                if(dp[l+1][r][0]-1>=a[l]){
                    chmax(dp[l][r][0],dp[l+1][r][0]-1);
                }
                chmax(dp[l][r][0],dp[l][r][1]-(w-1));
                chmax(dp[l][r][1],dp[l][r][0]-(w-1));
            }
        }
        if(max(dp[0][n][1],dp[0][n][0])>=0)ac=wj;
        else wa=wj;
    }
    cout<<ac<<"\n";
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    pass_time=clock();
    int t=1;
    //cin>>t;
    while(t--)solve();
    pass_time=clock()-pass_time;
    dbg(pass_time/CLOCKS_PER_SEC);
}
0