結果

問題 No.484 収穫
ユーザー beetbeet
提出日時 2018-11-06 13:49:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 819 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 204,100 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 22:12:42
合計ジャッジ時間 3,145 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,944 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
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  vector<Int> dp1(n,0),dp2(n,0);
  for(Int i=0;i<n;i++){
    if(i) chmax(dp1[i],dp1[i-1]+1);
    chmax(dp1[i],a[i]);                  
  }
  for(Int i=n-1;i>=0;i--){
    if(i+1<n) chmax(dp2[i],dp2[i+1]+1);
    chmax(dp2[i],a[i]);                  
  }

  Int ans=min(dp1[n-1],dp2[0]);
  for(Int i=0;i+1<n;i++){
    Int s=dp1[i]-i;
    Int t=dp2[i+1]-(n-(i+2));
    chmin(ans,max(dp1[i],t+(n-1)+i));
    chmin(ans,max(dp2[i],s+(n-1)+(n-(i+2))));
  }
  
  cout<<ans<<endl;
  return 0;
}
0