結果

問題 No.484 収穫
ユーザー PachicobuePachicobue
提出日時 2018-11-21 02:59:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 3,000 ms
コード長 1,039 bytes
コンパイル時間 2,647 ms
コンパイル使用メモリ 203,776 KB
実行使用メモリ 66,092 KB
最終ジャッジ日時 2023-08-26 02:33:41
合計ジャッジ時間 4,939 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 109 ms
65,944 KB
testcase_13 AC 110 ms
65,876 KB
testcase_14 AC 109 ms
65,932 KB
testcase_15 AC 109 ms
65,932 KB
testcase_16 AC 110 ms
65,864 KB
testcase_17 AC 110 ms
65,884 KB
testcase_18 AC 109 ms
65,792 KB
testcase_19 AC 109 ms
65,928 KB
testcase_20 AC 111 ms
65,832 KB
testcase_21 AC 109 ms
66,008 KB
testcase_22 AC 111 ms
66,092 KB
testcase_23 AC 109 ms
65,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 16;
int main()
{
    int N;
    std::cin >> N;
    std::vector<ll> A(N + 1);
    for (int i = 1; i <= N; i++) { std::cin >> A[i]; }
    std::vector<std::vector<ll>> l(N + 2, std::vector<ll>(N + 2, INF<ll>)), r(N + 2, std::vector<ll>(N + 2, INF<ll>));
    l[2][N] = A[1], r[1][N - 1] = A[N];
    for (int i = N - 2; i >= 0; i--) {
        for (int j = 1; j <= N - i; j++) {
            const int L = j, R = j + i;
            l[L + 1][R] = std::min(l[L + 1][R], std::max(l[L][R] + 1, A[L]));
            r[L][R - 1] = std::min(l[L][R - 1], std::max(l[L][R] + R - L + 1, A[R]));
            l[L + 1][R] = std::min(l[L + 1][R], std::max(r[L][R] + R - L + 1, A[L]));
            r[L][R - 1] = std::min(l[L][R - 1], std::max(r[L][R] + 1, A[R]));
        }
    }
    ll ans = INF<ll>;
    for (int i = 1; i <= N + 1; i++) { ans = std::min({ans, l[i][i - 1], r[i][i - 1]}); }
    std::cout << ans << std::endl;
    return 0;
}
0