結果

問題 No.484 収穫
ユーザー ei1333333ei1333333
提出日時 2017-02-07 09:30:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 3,000 ms
コード長 961 bytes
コンパイル時間 1,360 ms
コンパイル使用メモリ 158,816 KB
実行使用メモリ 66,156 KB
最終ジャッジ日時 2024-04-21 14:22:07
合計ジャッジ時間 2,677 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
65,992 KB
testcase_01 AC 19 ms
66,056 KB
testcase_02 AC 18 ms
65,980 KB
testcase_03 AC 18 ms
66,060 KB
testcase_04 AC 19 ms
66,096 KB
testcase_05 AC 18 ms
66,048 KB
testcase_06 AC 19 ms
66,148 KB
testcase_07 AC 19 ms
65,940 KB
testcase_08 AC 17 ms
65,872 KB
testcase_09 AC 18 ms
66,008 KB
testcase_10 AC 18 ms
66,060 KB
testcase_11 AC 18 ms
65,996 KB
testcase_12 AC 33 ms
66,064 KB
testcase_13 AC 34 ms
66,156 KB
testcase_14 AC 33 ms
66,048 KB
testcase_15 AC 34 ms
66,116 KB
testcase_16 AC 32 ms
66,028 KB
testcase_17 AC 34 ms
66,064 KB
testcase_18 AC 33 ms
66,080 KB
testcase_19 AC 33 ms
65,988 KB
testcase_20 AC 32 ms
66,096 KB
testcase_21 AC 33 ms
66,084 KB
testcase_22 AC 32 ms
66,080 KB
testcase_23 AC 32 ms
65,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;

inline void chmin(int64 &a, int64 b) { a = min(a, b); }

inline void chmax(int64 &a, int64 b) { a = max(a, b); }

const int64 INF = 1LL << 55;
int N, A[2003];
int64 dp[2003][2003][2];

int main()
{
  cin >> N;
  for(int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  fill_n(**dp, 2003 * 2003 * 2, INF);

  dp[2][N][0] = A[1];
  dp[1][N - 1][1] = A[N];

  for(int i = N - 2; i >= 0; i--) {
    for(int j = 1; j + i <= N; j++) {
      const int L = j, R = j + i;
      chmin(dp[L + 1][R][0], dp[L][R][0] + 1);
      chmin(dp[L + 1][R][0], dp[L][R][1] + i + 1);
      chmax(dp[L + 1][R][0], A[L]);
      chmin(dp[L][R - 1][1], dp[L][R][0] + i + 1);
      chmin(dp[L][R - 1][1], dp[L][R][1] + 1);
      chmax(dp[L][R - 1][1], A[R]);
    }
  }

  int64 ret = INF;
  for(int i = 1; i <= N + 1; i++) {
    chmin(ret, dp[i][i - 1][0]);
    chmin(ret, dp[i][i - 1][1]);
  }
  cout << ret << endl;
}
0