結果

問題 No.484 収穫
ユーザー simansiman
提出日時 2021-09-28 05:46:50
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,850 bytes
コンパイル時間 4,425 ms
コンパイル使用メモリ 105,976 KB
実行使用メモリ 66,104 KB
最終ジャッジ日時 2023-09-21 10:11:50
合計ジャッジ時間 5,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 21 ms
66,028 KB
testcase_18 AC 20 ms
66,048 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 21 ms
66,048 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;

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;
  }

  ll dp[2][N][N];
  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 = l + 1; r < N; ++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