結果

問題 No.484 収穫
ユーザー tossytossy
提出日時 2017-02-11 10:08:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 3,000 ms
コード長 1,420 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 167,420 KB
実行使用メモリ 34,888 KB
最終ジャッジ日時 2023-08-03 16:20:14
合計ジャッジ時間 3,373 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,608 KB
testcase_01 AC 12 ms
34,604 KB
testcase_02 AC 11 ms
34,648 KB
testcase_03 AC 11 ms
34,676 KB
testcase_04 AC 12 ms
34,624 KB
testcase_05 AC 11 ms
34,632 KB
testcase_06 AC 12 ms
34,680 KB
testcase_07 AC 11 ms
34,752 KB
testcase_08 AC 11 ms
34,624 KB
testcase_09 AC 12 ms
34,636 KB
testcase_10 AC 12 ms
34,612 KB
testcase_11 AC 12 ms
34,760 KB
testcase_12 AC 37 ms
34,764 KB
testcase_13 AC 38 ms
34,684 KB
testcase_14 AC 37 ms
34,700 KB
testcase_15 AC 37 ms
34,756 KB
testcase_16 AC 38 ms
34,640 KB
testcase_17 AC 38 ms
34,608 KB
testcase_18 AC 37 ms
34,764 KB
testcase_19 AC 37 ms
34,888 KB
testcase_20 AC 37 ms
34,636 KB
testcase_21 AC 38 ms
34,612 KB
testcase_22 AC 38 ms
34,712 KB
testcase_23 AC 37 ms
34,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long

int dp[2001][2001][2];

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];

  // dp[l][r][b] : [l,r]を未収穫で,b=0:左,b=1:右端を収穫可能な最短時刻
  fill(dp[0][0], dp[2001][0], INF);
  dp[0][n-1][0] = vec[0];
  dp[0][n-1][1] = vec[n-1];
  for(int d=n; d>1; d--){
    for(int l=0; l+d-1<n; l++){
      int r=l+d-1;
      dp[l+1][r][0] = min(dp[l+1][r][0], max(vec[l+1], dp[l][r][0] + 1));
      dp[l+1][r][1] = min(dp[l+1][r][1], max(vec[r], dp[l][r][0] + d-1));
      dp[l][r-1][0] = min(dp[l][r-1][0], max(vec[l], dp[l][r][1] + d-1));
      dp[l][r-1][1] = min(dp[l][r-1][1], max(vec[r-1], dp[l][r][1] + 1));
    }
  }
  int ans = INF;
  rep(i,n)rep(j,2) ans = min(ans, dp[i][i][j]);
  cout<<ans<<endl;

  return 0;
}
0