結果

問題 No.484 収穫
ユーザー simansiman
提出日時 2021-09-28 05:50:58
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,854 bytes
コンパイル時間 6,186 ms
コンパイル使用メモリ 106,312 KB
実行使用メモリ 67,360 KB
最終ジャッジ日時 2023-09-21 10:16:30
合計ジャッジ時間 3,923 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
67,160 KB
testcase_01 AC 17 ms
67,164 KB
testcase_02 AC 16 ms
67,260 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 18 ms
67,216 KB
testcase_05 AC 17 ms
67,228 KB
testcase_06 AC 16 ms
67,224 KB
testcase_07 AC 17 ms
67,236 KB
testcase_08 AC 16 ms
67,288 KB
testcase_09 AC 17 ms
67,316 KB
testcase_10 AC 17 ms
67,292 KB
testcase_11 AC 18 ms
67,168 KB
testcase_12 AC 31 ms
67,312 KB
testcase_13 AC 30 ms
67,180 KB
testcase_14 AC 31 ms
67,280 KB
testcase_15 AC 31 ms
67,280 KB
testcase_16 AC 30 ms
67,184 KB
testcase_17 AC 30 ms
67,240 KB
testcase_18 AC 29 ms
67,276 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 31 ms
67,208 KB
testcase_23 AC 30 ms
67,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
ll dp[2][2020][2020];

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);

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

  if (N == 1) {
    cout << A[0] << endl;
    return 0;
  }

  memset(dp, -1, sizeof(dp));
  dp[0][1][N - 1] = A[0];
  dp[1][0][N - 2] = A[N - 1];

  for (int l = 0; l < N; ++l) {
    for (int r = N - 1; r > l; --r) {
      if (dp[0][l][r] != -1) {
        ll next_l_l_time = max(A[l], dp[0][l][r] + 1);
        if (dp[0][l + 1][r] == -1) {
          dp[0][l + 1][r] = next_l_l_time;
        }
        dp[0][l + 1][r] = min(dp[0][l + 1][r], next_l_l_time);

        ll next_l_r_time = max(A[r], dp[0][l][r] + r - (l - 1));
        if (dp[1][l][r - 1] == -1) {
          dp[1][l][r - 1] = next_l_r_time;
        }
        dp[1][l][r - 1] = min(dp[1][l][r - 1], next_l_r_time);
      }
      if (dp[1][l][r] != -1) {
        ll next_r_l_time = max(A[l], dp[1][l][r] + (r + 1) - l);
        if (dp[0][l + 1][r] == -1) {
          dp[0][l + 1][r] = next_r_l_time;
        }
        dp[0][l + 1][r] = min(dp[0][l + 1][r], next_r_l_time);

        ll next_r_r_time = max(A[r], dp[1][l][r] + 1);
        if (dp[1][l][r - 1] == -1) {
          dp[1][l][r - 1] = next_r_r_time;
        }
        dp[1][l][r - 1] = min(dp[1][l][r - 1], next_r_r_time);
      }
    }
  }

  ll ans = LLONG_MAX;

  for (int i = 0; i < N; ++i) {
    ll time = max(dp[0][i][i], dp[1][i][i]);
    if (time == -1) continue;
    // fprintf(stderr, "i: %d, (%lld, %lld)\n", i, dp[0][i][i], dp[1][i][i]);
    ans = min(ans, max(max(dp[0][i][i], dp[1][i][i]) + 1, A[i]));
  }

  cout << ans << endl;

  return 0;
}
0