結果

問題 No.484 収穫
ユーザー tossytossy
提出日時 2017-02-11 10:08:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 3,000 ms
コード長 1,420 bytes
コンパイル時間 1,984 ms
コンパイル使用メモリ 165,516 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-21 14:27:18
合計ジャッジ時間 3,453 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
34,816 KB
testcase_01 AC 23 ms
34,816 KB
testcase_02 AC 23 ms
34,688 KB
testcase_03 AC 23 ms
34,560 KB
testcase_04 AC 24 ms
34,560 KB
testcase_05 AC 24 ms
34,816 KB
testcase_06 AC 24 ms
34,688 KB
testcase_07 AC 24 ms
34,688 KB
testcase_08 AC 24 ms
34,560 KB
testcase_09 AC 25 ms
34,688 KB
testcase_10 AC 24 ms
34,816 KB
testcase_11 AC 24 ms
34,560 KB
testcase_12 AC 54 ms
34,944 KB
testcase_13 AC 54 ms
34,944 KB
testcase_14 AC 54 ms
34,816 KB
testcase_15 AC 54 ms
34,944 KB
testcase_16 AC 53 ms
34,688 KB
testcase_17 AC 54 ms
34,816 KB
testcase_18 AC 54 ms
34,816 KB
testcase_19 AC 53 ms
34,688 KB
testcase_20 AC 54 ms
34,688 KB
testcase_21 AC 53 ms
34,816 KB
testcase_22 AC 54 ms
34,688 KB
testcase_23 AC 52 ms
34,816 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