結果

問題 No.484 収穫
ユーザー beetbeet
提出日時 2018-11-06 17:03:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 3,000 ms
コード長 864 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 204,340 KB
実行使用メモリ 35,440 KB
最終ジャッジ日時 2024-04-30 22:16:48
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
35,432 KB
testcase_01 AC 9 ms
35,384 KB
testcase_02 AC 10 ms
35,328 KB
testcase_03 AC 9 ms
35,436 KB
testcase_04 AC 8 ms
35,304 KB
testcase_05 AC 9 ms
35,360 KB
testcase_06 AC 10 ms
35,352 KB
testcase_07 AC 10 ms
35,332 KB
testcase_08 AC 10 ms
35,392 KB
testcase_09 AC 10 ms
35,324 KB
testcase_10 AC 9 ms
35,396 KB
testcase_11 AC 9 ms
35,292 KB
testcase_12 AC 40 ms
35,416 KB
testcase_13 AC 44 ms
35,440 KB
testcase_14 AC 43 ms
35,308 KB
testcase_15 AC 43 ms
35,340 KB
testcase_16 AC 43 ms
35,372 KB
testcase_17 AC 42 ms
35,424 KB
testcase_18 AC 41 ms
35,420 KB
testcase_19 AC 42 ms
35,428 KB
testcase_20 AC 40 ms
35,380 KB
testcase_21 AC 42 ms
35,400 KB
testcase_22 AC 41 ms
35,316 KB
testcase_23 AC 43 ms
35,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 2020;
const Int INF = 1e15;
Int dp[MAX][MAX];
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=INF;

  dp[0][n-1]=0;
  dp[n-1][0]=0;

  for(Int w=n;w>1;w--){
    for(Int i=0;i+w-1<n;i++){
      Int j=i+w-1;
      chmin(dp[i][j],dp[j][i]+(j-i-1));
      chmin(dp[j][i],dp[i][j]+(j-i-1));

      chmin(dp[i+1][j],max(dp[i][j],a[i])+1);
      chmin(dp[j-1][i],max(dp[j][i],a[j])+1);
    }
  }
  
  Int ans=INF;
  for(Int i=0;i<n;i++) chmin(ans,max(dp[i][i],a[i]));

  cout<<ans<<endl;
  return 0;
}
0