結果

問題 No.484 収穫
ユーザー 0w10w1
提出日時 2017-09-15 04:48:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 915 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 194,252 KB
実行使用メモリ 66,176 KB
最終ジャッジ日時 2024-04-25 11:00:04
合計ジャッジ時間 7,037 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
65,920 KB
testcase_01 AC 46 ms
66,176 KB
testcase_02 AC 46 ms
66,048 KB
testcase_03 AC 46 ms
66,176 KB
testcase_04 AC 46 ms
65,920 KB
testcase_05 AC 48 ms
66,176 KB
testcase_06 AC 46 ms
66,048 KB
testcase_07 AC 46 ms
66,176 KB
testcase_08 AC 47 ms
66,048 KB
testcase_09 AC 48 ms
65,920 KB
testcase_10 AC 49 ms
66,048 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T1, class T2>
int upmin(T1 &x, T2 v) {
  if (x <= v) return 0;
  return x = v, 1;
}

const int MAXN = 2000;

int N;
int A[MAXN];

long long dp[MAXN][MAXN + 1][2];

int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[1][N][0] = A[0];
  dp[0][N - 1][1] = A[N - 1];
  for (int len = N - 1; len; --len) {
    for (int i = 0; i + len <= N; ++i) {
      if (i > 0) {
        upmin(dp[i + 1][i + len][0], max(1LL * A[i], dp[i][i + len][0] + 1));
      }
      if (i + len < N) {
        upmin(dp[i][i + len - 1][1], max(1LL * A[i + len], dp[i][i + len][1] + 1));
      }
    }
  }
  long long ans = 0x3f3f3f3f3f3f3f3fLL;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j < 2; ++j) {
      upmin(ans, dp[i][i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
0