結果

問題 No.484 収穫
ユーザー ei1333333ei1333333
提出日時 2016-11-30 15:04:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 920 bytes
コンパイル時間 1,150 ms
コンパイル使用メモリ 144,880 KB
実行使用メモリ 35,024 KB
最終ジャッジ日時 2023-08-25 22:27:26
合計ジャッジ時間 2,855 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
35,008 KB
testcase_01 AC 13 ms
34,704 KB
testcase_02 AC 13 ms
34,684 KB
testcase_03 AC 13 ms
34,704 KB
testcase_04 AC 13 ms
34,780 KB
testcase_05 AC 13 ms
34,724 KB
testcase_06 WA -
testcase_07 AC 13 ms
34,744 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 32 ms
34,708 KB
testcase_13 AC 33 ms
34,708 KB
testcase_14 AC 32 ms
34,820 KB
testcase_15 AC 31 ms
34,696 KB
testcase_16 AC 32 ms
34,888 KB
testcase_17 AC 31 ms
34,816 KB
testcase_18 AC 31 ms
34,712 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 32 ms
34,900 KB
testcase_23 AC 32 ms
34,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

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

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

const int INF = 1 << 30;
int N, A[2003];
int 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] + j + 1);
      chmax(dp[L + 1][R][0], A[L]);
      chmin(dp[L][R - 1][1], dp[L][R][0] + j + 1);
      chmin(dp[L][R - 1][1], dp[L][R][1] + 1);
      chmax(dp[L][R - 1][1], A[R]);
    }
  }

  int 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