結果

問題 No.484 収穫
ユーザー shossiissohsshossiissohs
提出日時 2018-01-16 17:07:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 3,000 ms
コード長 866 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 144,880 KB
実行使用メモリ 66,432 KB
最終ジャッジ日時 2023-08-25 18:43:12
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
66,124 KB
testcase_01 AC 19 ms
66,192 KB
testcase_02 AC 19 ms
66,172 KB
testcase_03 AC 19 ms
66,184 KB
testcase_04 AC 19 ms
66,216 KB
testcase_05 AC 18 ms
66,184 KB
testcase_06 AC 19 ms
66,300 KB
testcase_07 AC 18 ms
66,420 KB
testcase_08 AC 18 ms
66,128 KB
testcase_09 AC 20 ms
66,188 KB
testcase_10 AC 20 ms
66,208 KB
testcase_11 AC 20 ms
66,168 KB
testcase_12 AC 53 ms
66,424 KB
testcase_13 AC 53 ms
66,252 KB
testcase_14 AC 54 ms
66,260 KB
testcase_15 AC 54 ms
66,316 KB
testcase_16 AC 53 ms
66,252 KB
testcase_17 AC 54 ms
66,320 KB
testcase_18 AC 53 ms
66,432 KB
testcase_19 AC 53 ms
66,308 KB
testcase_20 AC 53 ms
66,312 KB
testcase_21 AC 53 ms
66,260 KB
testcase_22 AC 54 ms
66,312 KB
testcase_23 AC 53 ms
66,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int n;
ll memo[2005][2005][2];
ll a[2005];
const ll INF = 1e12;

ll rec(int l, int r, int d) {
  if(memo[l][r][d] >= 0) return memo[l][r][d];

  ll res = INF;
  if(l == 0 && r == n-1) {
    if(d == 0) res = a[0];
    else res = a[n-1];
  }
  else {
    if(d == 0) {
      if(l) res = min(res,rec(l-1,r,0) + 1);
      if(r < n - 1) res = min(res,rec(l,r+1,1) + r - l + 1);
      res = max(res,a[l]);
    }
    else {
      if(r < n - 1) res = min(res,rec(l,r+1,1) + 1);
      if(l) res = min(res,rec(l-1,r,0) + r - l + 1);
      res = max(res,a[r]);
    }
  }
  return memo[l][r][d] = res;
}
      
int main() {
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  memset(memo,-1,sizeof memo);
  ll ans = INF;
  for(int i = 0; i < n; i++) ans = min(ans,rec(i,i,0));

  cout << ans << endl;
}
  
0