結果

問題 No.484 収穫
ユーザー rapurasurapurasu
提出日時 2017-02-15 23:16:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,264 ms / 3,000 ms
コード長 1,561 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 158,632 KB
実行使用メモリ 34,928 KB
最終ジャッジ日時 2024-04-21 14:29:47
合計ジャッジ時間 19,849 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
34,788 KB
testcase_01 AC 15 ms
34,660 KB
testcase_02 AC 14 ms
34,816 KB
testcase_03 AC 16 ms
34,628 KB
testcase_04 AC 15 ms
34,788 KB
testcase_05 AC 16 ms
34,688 KB
testcase_06 AC 15 ms
34,584 KB
testcase_07 AC 15 ms
34,660 KB
testcase_08 AC 14 ms
34,708 KB
testcase_09 AC 14 ms
34,816 KB
testcase_10 AC 15 ms
34,688 KB
testcase_11 AC 15 ms
34,688 KB
testcase_12 AC 1,271 ms
34,816 KB
testcase_13 AC 2,246 ms
34,816 KB
testcase_14 AC 1,593 ms
34,928 KB
testcase_15 AC 1,511 ms
34,724 KB
testcase_16 AC 2,264 ms
34,900 KB
testcase_17 AC 15 ms
34,580 KB
testcase_18 AC 15 ms
34,688 KB
testcase_19 AC 2,221 ms
34,816 KB
testcase_20 AC 2,222 ms
34,836 KB
testcase_21 AC 2,237 ms
34,900 KB
testcase_22 AC 1,830 ms
34,832 KB
testcase_23 AC 22 ms
34,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[2001];
LL dp[2001][2001];
LL m=0;
//左→右
LL lr(int x,int y){
   LL ans=A[x];
   for(int i=x+1;i<=y;i++){
       ans=max(ans+1,A[i]);
   }
   return ans;
}
//右→左
LL rl(int x,int y){
   LL ans=A[x];
   for(int i=x-1;i>=y;i--){
       ans=max(ans+1,A[i]);
   }
   return ans;
}

LL solve_right(int r,int l);
LL solve_left(int l,int r){
   if(dp[l][r]!=-1)return dp[l][r];
   if(l==r)return A[l];
   LL ans=1000000000000;
   LL calc=lr(l,r);
   ans=calc;
   if(A[l]+2*(r-l)-1<=m){
      ans=min(ans,solve_left(l+1,r));
      ans=min(ans,solve_right(r,l+1));
   }
   if(A[l]+(r-l)<=A[r])ans=min(ans,solve_right(r,l+1));
   dp[l][r]=ans;
  // cout<<"l:r="<<l<<":"<<r<<" ans"<<ans<<endl;
   return ans;
}

LL solve_right(int r,int l){
   if(dp[r][l]!=-1)return dp[r][l];
   if(l==r)return A[l];
   LL ans=1000000000000;
   LL calc=rl(r,l);
   ans=calc;
   if(A[r]+2*(r-l)-1<=m){
      ans=min(ans,solve_right(r-1,l));
      ans=min(ans,solve_left(l,r-1));
   }
   if(A[r]+(r-l)<=A[r])ans=min(ans,solve_right(l,r-1));
   dp[r][l]=ans;
   return ans;
}

int main(){
        REP(i,2001){
            REP(j,2001){
                dp[i][j]=-1;
            }
        }
	cin>>N;
	REP(i,N){
	    cin>>A[i];
	    m=max(m,A[i]);
	}
        cout<<min(solve_left(0,N-1),solve_right(N-1,0))<<endl;
	return(0);
}
0